question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

combineSagas utility funciton

See original GitHub issue

At the moment we have to do something like

export default function* root() {
    yield [
        fork(saga1),
        fork(saga2),
        fork(saga3),
        fork(saga4)
    ];
}

Would be great to have combineSagas just like redux’s combineReducers. Use it like

export default rootSaga = combineSagas({
    saga1,
    saga2,
    ...
});

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

24reactions
yjcxy12commented, Mar 7, 2016

I was more aware of the project structural similarities. I’d have “reduces” folder, contains different reducers, and in index.js it would be something like:

import { combineReducers } from 'redux';
import firstReducer from './firstReducer';
import secondReducer from './secondReducer';
import thirdReducer from './thirdReducer';

const rootReducer = combineReducers({
    firstReducer,
    secondReducer,
    thirdReducer
});

export default rootReducer;

I’ve tried to find a way to sort of “combine” all different sagas into a single rootSaga, so that it can be passed into createSagaMiddleware. Couldn’t find it on docs, but in examples it had a pattern. And the “sagas” folder is very similar to “reducers” - having different sagas, and an index.js that exports rootSaga.

import { fork } from 'redux-saga/effects';
import firstSaga from './firstSaga';
import secondSaga from './secondSaga';
import thirdSaga from './thirdSaga';

export default function* rootSaga() {
    yield [
        fork(firstSaga),
        fork(secondSaga),
        fork(thirdSaga),
    ];
}

Just with weird syntax for someone just starting up with redux-saga like me.

Agreed that it’s only very little boilerplate, but at least a mention of creating rootSaga in docs would be great.

10reactions
Andaristcommented, Nov 16, 2017

@alfonsodev the downside is that you create iterators here, they will have different identities with each run, so its harder to test. You are also yielding an array, which is deprecated now - you should wrap that array in all effect.

Idiomatic way of using redux-saga is to yield effects (description object) only, although yielding promises and iterators is allowed.

It is also super easy to adjust your code to use effects:

export default function* rootSaga() {
  yield all(map(key => fork(combinedSagas[key]), Object.keys(combinedSagas)))
}

or event shorter

export default function* rootSaga() {
  yield all(map(fork, combinedSagas))
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

The Electric Side of Combination Gas-Electric Utilities - jstor
This paper assesses the effects of combination gas-electric utilities on income redistribution and economic efficiency. It finds that such com-.
Read more >
How a Combined Cycle Power Plant Works - TVA
Combined cycle technology allows a power plant to generate 50 percent more electricity from its fuel than it could with a single-cycle power...
Read more >
Successful Practices in Combined Gas and Electric Utility ...
and natural gas utilities to operate their own separate programs. ... In contrast, combined natural gas and electric energy efficiency programs can create....
Read more >
Combined cycle power plant - Wikipedia
A combined cycle power plant is an assembly of heat engines that work in tandem from the same source of heat, converting it...
Read more >
Combined Cycle Power Plant | GE Gas Power
This is how a combined-cycle plant works to produce electricity and captures waste heat from the gas turbine to increase efficiency and electrical...
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found