-
Notifications
You must be signed in to change notification settings - Fork 15
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
feature/before-route-change #12
feature/before-route-change #12
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Only issue is that we need to ensure that beforeRouteChange
runs before the matched route saga.
src/router.js
Outdated
@@ -56,6 +56,10 @@ export default function router(history, routes) { | |||
if (match) { | |||
lastMatch = match; | |||
effects.push(spawn(match.action, match.params)); | |||
|
|||
if ('beforeRouteChange' in options) { | |||
effects.unshift(spawn(options.beforeRouteChange, match.params)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By placing this in the array, it will potentially run in parallel to the matched route instead of technically running before it. We'll need to ensure that it can run first. If you need any help with this, let me know.
76f0062
to
15460d0
Compare
I have reimplemented it in a synchronous manner by adding an optional extra state. I hope that you'll like the solution :) |
src/router.js
Outdated
next: HANDLE_LOCATION, | ||
}; | ||
}, | ||
|
||
[HANDLE_LOCATION](location, fsm) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we hit this line after BEFORE_HANDLE_LOCATION, we will have lost reference to the location
. In fact, the location
argument will be equal to a task object that redux-saga will return for the spawn
effect. We'll need to probably save a reference to the location. Maybe create a let currentLocation
with the other let
declarations above? Then HANDLE_LOCATION will have to use the currentLocation
if the location
argument is missing.
We'll also need another state after BEFORE_HANDLE_LOCATION. While the spawn
is outside the array now, it is still a non-blocking effect in redux-saga, meaning it has the potential to run concurrently with the matched saga. If you add an additional state, you can use the join
effect on the task to basically wait for the beforeRouteChange
saga to finish before handling the location with the route saga.
This is a good start @TeoTN! I left some more detail in my review comment. Please let me know if my comment makes sense. Also, working with |
6649fa0
to
d62f102
Compare
Thanks for your review @jfairbank! You've pointed out a few quite important things that I had overlooked. |
This looks good, @TeoTN. Good job! I'll work on a release soon. Thanks! |
Thanks! |
Implement #8 - optional parallel call to a saga before any other sagas