-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Add ability to create daemon sagas #1315
Conversation
1 similar comment
@justingreenberg what do you think about this change? |
@afitiskin awesome work :) @mxstbr this change will definitely achieve stated goal, but i'm still reluctant to move any additional logic into our internal utilities... inevitbably newcomers will mistake our tl;dr - this is awesome work by @afitiskin, but i would probably wait for next major release and move helpers into external package as discusssed |
Sure, sounds good to me. Thank you @afitiskin for taking the time to kick off this discussion and taking the time to submit a PR! |
This looks awesome 🎉 Between the switch to Jest, replacing Post-CSS with Styled-components and now Daemon sagas... With a little documentation for Daemon sgas, I'd say we're very ready for 3.4.0. Thoughts? |
Did you see that I closed this PR? 😉 But we should def ship a new version asap! |
I did, but I'm suggesting that it be included in the same (next?) release that also contains Jest and Styled Components. Those three make a pretty big change, I think worthy of at least a minor version bump. |
Yeah need to publish 3.4 already! Will get to that soon. |
I see the issue of appearing to 'pollute' redux-saga api, but this issue is a frequent source of confusion as it is. I seriously think the confusion caused by this change is the lesser evil. I vote to reopen and merge this PR. Regardless, documentation is the answer to either problem. @afitiskin On the redux-saga project there are (currently) 15 issues returned on a search for "duplicate". Consider opening a PR there to make |
@gihrig i'm sorry this issue is still coming up so much... it's frustrating because i so want it to be a learning experience, after all it's just javascript 😜 anyway this specific issue has come up so many times, it probably sensible to address it. with respect to this PR, i can say it is the most elegant of the proposed "solutions" i've seen. what bugs me is that the "problem" is described as a saga duplication issue, when it isn't. the real issue is that users want to bind daemon sagas to component lifecycle, in the case of our demo it's a route handler loading data. our current implementation (even after merging this PR) was written for the demo—there are better solutions for route-based data loading https://github.com/jfairbank/redux-saga-routerif you know your route map/data needs in advance, this tool syncs directly with history/router // sagas.js
import { router } from 'redux-saga-router'
function * rootSaga () {
yield * router(history, {
* '/' () {
yield fork(takeLatest, LOAD_REPOS, getRepos)
}
})
} https://github.com/threepointone/react-redux-sagathis is super simple, component/react lifecycle based // containers/HomePage/index.js
export class HomePage extends React.PureComponent {
render() {
//...
return (
<article>
<Saga saga={getReposWatcher} /> // cancelled on unmount
// ... even lifecycle hooks combined with edit: references for discussion -
|
@justingreenberg As always, thanks for the deeper insight ✨ Do you think it would be a good idea to integrate a redux-saga-router based solution into the example app as a demonstration of best practice? Pros/cons? |
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. |
This PR fixes #1183 with 100% backward compatibility. Now we are able to create daemon sagas. Daemon sagas run only once (when loaded), next time injector ignore them. So, we don't need to track
LOCATION_CHANGE
and manually stop simple sagas to prevent duplicates: we just need to setisDaemon
attribute of saga totrue
and that's it!Before:
After: