Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #276 #288

Merged
merged 4 commits into from
Sep 17, 2018
Merged

fix #276 #288

merged 4 commits into from
Sep 17, 2018

Conversation

connorsmallman
Copy link
Contributor

Update state when action has kind of 'push'

Updating the state forces the current route thunk to be called again allowing a refresh of the current route.

@connorsmallman connorsmallman changed the title #276 fix #276 Sep 13, 2018
@connorsmallman
Copy link
Contributor Author

@sergio-toro is that what you had in mind for the fix?

@sergio-toro
Copy link
Contributor

@connorsmallman I've added a special case to update only kind in the state, otherwise, it will set prev as the same route.

@ScriptedAlchemy / @hedgepigdaniel do you mind taking a look?

@ScriptedAlchemy
Copy link
Collaborator

Will take a look today! 🙏

Copy link
Contributor

@hedgepigdaniel hedgepigdaniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic + tests looks correct to me

@@ -41,6 +41,20 @@ export default (initialState: LocationState, routesMap: RoutesMap) => (
routesMap
}
}
else if (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this needs to be a separate if/else branch instead of adding another clause on in the condition of the first if statement line 27 such as ... || action.meta.location.kind !== state.kind)?

If the condition is getting too complex, perhaps its worth splitting it out into a helper function, e.g. shouldRefreshState? Not a big deal, it just seems unfortunate to introduce an extra case if it could be covered by the first one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case only needs to update the kind variable when the pathname and search are the same.
If we do a full update it will store on state.prev the same location, which It feels wrong because we haven't transitioned to a new route, we just need to call the thunk.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hedgepigdaniel Thanks for pointing, the condition was not correct. I've updated it to the expected case (pathname and query equal but kind updated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants