salsita / prism

React / Redux action composition made simple http://salsita.github.io/prism/
496 stars 24 forks source link

[docs] Explain multiple sagas with takeEvery #43

Closed jmatsushita closed 7 years ago

jmatsushita commented 8 years ago

Hi there,

What's the redux-elm idiomatic way to route events to different sagas?

Right now I do this:

function* saga() {
  yield* takeEvery(['SOMETHING', 'OTHERTHING'], doTHINGS);
}

Where doTHINGS branches to doSOMETHING and doOTHERTHING but I'd like to write something like what case is doing such as:

function* saga() {
  yield* takeEveryCase()
    .case('SOMETHING', doSOMETHING)
    .case('OTHERTHING', doOTHERTHING)
}

Or a variation on this.

Am I missing something obvious?

eliperelman commented 8 years ago

@jmatsushita

Typically I structure my reducer like the following for different action-to-saga handlers:

import { takeEvery } from 'redux-saga';
import { fork } from 'redux-saga/effects';

function* doSomething() {
  // ...
}

function* doOtherThing() {
  // ...
}

function* listener() {
  yield [
    fork(takeEvery, 'SOMETHING', doSomething),
    fork(takeEvery, 'OTHERTHING', doOtherThing)
  ];
}

export default new Updater(initialModel, listener)
  .toReducer();
jmatsushita commented 8 years ago

A thing of beauty. Thanks! It should make it's way to the docs :)

tomkis commented 8 years ago

This is certainly the right way to do it, however I do not think this should be part of the redux-elm docs, especially when I am planning to support rxjs as alternative saga implementation.

tomkis commented 7 years ago

Closing, nothing actionable here.