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 #1518: Move root route configuration to routes.js, add documentation for creating a global saga #1545
Conversation
…ating a global saga (#1518)
@RobertSheaO Thanks for cleaning up the PR! ✨ I'll be watching the discussion in #1518. |
This is awesome. Quick question- why is there no saga in I love the overall idea. Although, there seems to be a working solution for this particular problem, this PR solves two problems:
That being said, I haven't studied other implementations. There's a nice comment from @justingreenberg but that involves installing I'd love to know what others think of this. |
Ah, good catch. I'll update the PR with that change. As for the missing
app/sagas.js, I didn't want to put it in the base app, as not everyone will
need it.
…On Wed, Feb 1, 2017 at 02:08 Mihir Karandikar ***@***.***> wrote:
This is awesome. Quick question- why is there no saga in App/? I had to
remove sagas and injectSagas(sagas.default); from the route config.
Precisely, from here
<https://github.com/RobertSheaO/react-boilerplate/blob/bb69de2e18fd690560f613bef001b1d606f8df37/app/routes.js#L65>
to get it to work properly.
I love the overall idea. Although, there seems to be a working solution
<#1277 (comment)>
for this particular problem, this PR solves two problems:
1. Creates a good, if not ideal, example for developers of
implementing app-level sagas.
2. Unifies route configuration in a single file.
That being said, I haven't studied other implementations. There's a nice
comment <https://github.com/justingreenberg> from @justingreenberg
<https://github.com/justingreenberg> but that involves installing
redux-saga-router.
I'd love to know what others think of this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1545 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA6uhc4S8WSuO3yEova3t3tmWcQWeJv2ks5rYFmUgaJpZM4LyC7O>
.
|
@RobertSheaO No problem! :)
True. But IMO, moving some of the repo-loading logic in the global saga would demonstrate its use in a better way. It'll be easiers for developers to understand and adopt this approach if they see the actual code. |
@KarandikarMihir I agree that a built-in usage example would be great. Not sure about repo-loading, since that only happens on submit; however, I could perhaps add an example of preloading @mxstbr 's repos on app load. Thoughts? |
@KarandikarMihir The "nice comment" link got changed to JK's profile page ???
@RobertSheaO How about pulling the current GH star count for react-boilerplate? |
Sounds good, I'll add that and update my PR |
Nice work! So another option for app-level sagas, and user authentication sagas, which I think this PR solves, is using a Provider similar to how While app-level sagas could still be useful, I think at least for user authentication, a Provider is a better pattern/implementation. Thoughts? |
@gihrig Sorry! Here's the correct link |
There are a number of open issues surrounding difficulties with sagas and the way they are handled. Ref: #1384, #1420, #1315, #1518, #1447 and this PR #1545. I'm concerned about the lack of real-world experience behind these various proposals. The only two I know of having been applied are #1420 used in production by @adelsz and and #1447 used in production by @jeffbski, but not with react-boilerplate. @kopax has experience with #1447Comment and react-boilerplate. Perhaps he can update us with his experience so far. I'm personally leaning toward #1447 (redux-logic) and possibly some combination of other proposals, but have not gotten far enough into this to make a firm stand. If anyone is interested, I have updated @jeffbski's fork to the 3.4 react-boilerplate release. What I would really like to see, is for basic requirements of a simple addition to the example app to be drawn up, such as implementation of a simple login facility for example, then implemented in each proposal. I think the experience of those implementing the same set of requirements in the several proposed changes to RBP async handling would be enlightening. more at #1554 - Thanks @marcandrews |
I've been busy these past few days; however, I'll whip up an example to put into the example app. I'll also read over the above linked issues to see how they impact what I'm doing. Personally, I like the simplicity of this solution, since it uses sagas in the same exact way as all the other sagas. For my particular use case, this is how I am using them:
routes.js ...
const { injectReducer, injectSagas, redirectToLogin } = getAsyncInjectors(store);
...
{
path: '/',
name: 'home',
onEnter: redirectToLogin,
getComponent(nextState, cb) {
...
},
} asyncInjectors.js function redirectToLogin(store) {
return (nextState, replaceState) => {
// Look into store for token, if invalid, replaceState with the `/login` path.
}
App/index.js componentWillMount() {
if (accessTokenIsValid) {
if (!this.props.accountDetails) this.props.onLoadAccountDetails();
}
} |
@marcandrews See my above comment about using |
// create reusable async injectors using getAsyncInjectors factory | ||
const { injectReducer, injectSagas } = getAsyncInjectors(store); | ||
|
||
childRoutes : [ |
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.
childRoutes = [
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.
need to fix the doc
|
||
Like other sagas, your global saga will live within a container, the `App` container. Go ahead and add a file and use the following starter code; it's the same starter code for other sagas. | ||
|
||
######app/containers/App/sagas.js |
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.
###### app/containers/App/sagas.js
``` | ||
|
||
Next we'll import the `sagas.js` file into our `App` route configuration by updating our `getComponent` function to asynchronosly load our files. You can just replace it with the one below. | ||
######app/routes.js |
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.
###### app/routes.js
please merge |
Deploy preview failed. Built with commit 2e57793 https://app.netlify.com/sites/react-boilerplate/deploys/59690735a700c4681563d721 |
@RobertSheaO thank you so much for your contribution :) as we have just upgraded to RR v4 and refactored |
I’ll take a look. Thank you.
…On Fri, Jul 21, 2017 at 12:42 AM Justin Greenberg ***@***.***> wrote:
Closed #1545
<#1545>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1545 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA6uhYBg29lhDlmTboZhAZTH2jwAZo7Mks5sQFZOgaJpZM4LyC7O>
.
|
What happened to this? docs/js/global-saga..md no longer exists??? What is the recommended approach now? |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Fix for issue #1518. The route configuration was previously split between
app.js
androutes.js
. I've moved theApp
(rootRoute) configuration to theroutes.js
file, so it is all in one place. I also changed loading the root route to usegetComponent
, instead ofcomponent
, to make it easier for people to implement a global saga if they want to do that. There is also new documentation on how to add a global saga. I've also updated the spacing for the route generators and tested them.Original Pull Request Here: #1538