Ducks + sagas
See original GitHub issueI use ducks modules i my projects. I think that sagas must be a part of ducks module. But there is a problem with watchers-sagas that we must run. I write lite saga-manager class, which help me to create root saga. Its usage looks like this:
/*
* auth module
*/
// reducer, actions....
// sagas
function *fetchAuthSaga () { ... }
function *loginSaga () { ... }
function *logoutSaga () { ... }
sagasManager.addSagaToRoot(function *watcher() {
yield [
takeEvery(FETCH, fetchAuthSaga),
takeEvery(LOGOUT, logoutSaga),
takeEvery(LOGIN, loginSaga),
];
});
I do the same things in all modules with sagas. Then i just run root saga:
// index.js
const store = configureStore();
store.runSaga(sagasManager.getRootSaga());
I think that sagasManager is missing part of redux-saga library even if you dont use ducks modules. In a large project there are a lot of sagas in separate files.
Here my implementation of sagasManager:
import { fork } from 'redux-saga/effects';
class SagasManager {
constructor() {
this.sagasWithArguments = [];
}
addSagaToRoot(...sagaWithArguments) {
this.sagasWithArguments.push([...sagaWithArguments]);
}
getRootSaga() {
const self = this;
return function *rootSaga() {
yield self.sagasWithArguments.map((sagaWithArguments) => fork(...sagaWithArguments));
};
}
}
export default new SagasManager;
PS: Sorry my poor English
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top Results From Across the Web
saga-duck - npm
extensible and composable duck for redux-saga, support typescript 3+.. Latest version: 3.4.8, last published: 16 days ago.
Read more >React + Re-ducks + Redux + Saga | limkopi.me
I like the idea of separating presentational components and smart components (containers). The idea is dead simple but this React pattern has a...
Read more >Scaling your Redux App with ducks - freeCodeCamp
To represent chained operations you need a redux middleware to enhance the dispatch function. Some popular examples are: redux-thunk, redux-saga ...
Read more >Redux Ducks Pattern as an ES6 Class for REST APIs
The redux application is contained within a JavaScript ES6 class. · The constructor only takes 2 arguments, the name of the app and...
Read more >redux-saga ducks counter - CodeSandbox
redux-saga ducks counter ... components. containers. pages. sagas. store. index.js. styles.css. package.json. Dependencies.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kamleshchandnani just use this in ur split bundle
or depending on how much involved in this
sagasManager
you are you may need to tweak it a little bit. i.e. like this:Inspect with a debugger this line
const initialSagas = yield flush(sagasChannel);
- somehowsagasChannel
is referencingloginSaga
(or some similar one), when it should be a channel’s instance. Should be easily fixable - I’ve written this tweaked code in a rush and ofc didnt test it properly.