erikras / multireducer

A utility to wrap many copies of a single Redux reducer into a single key-based reducer.
MIT License
422 stars 23 forks source link

Multireducer, Redux Saga, wrapAction #111

Closed nabati closed 7 years ago

nabati commented 8 years ago

I'm wondering if there's a canonical way of put()ing actions using Redux Saga. Simply calling put() with the created action won't work in conjunction with multireducer since we're not supplying a reducerKey.

Looking at the previous releases, it seems like it was just recently that wrapAction was removed from the public api. Was there a reason for removing this? If not, I suggest exporting it once again, since it seems to allow a cleaner integration with Redux Saga than calling a wrapped dispatch.

What's your opinion?

nabati commented 8 years ago

On a similar note, is there a canonical way of, from within a saga, matching an action "routed" for a specific reducer? For now I'm making use of something like

action.meta.__multiReducerKey == 'myKey', but this is just a temporary solution of course as it doesn't make sense of explicitly making use an (undocumented) implementation detail in this manner.

yesmeck commented 8 years ago

Basically, the put function in Redux Saga is equivalent to dispatch, so that you can do like this:

import { wrapDispatch } from 'multireducer'

function* foo() {
  // blah blah
  yield wrapDispatch(put, 'active')(barAction())
}

matching an action "routed" for a specific reducer?

Why do you want to route action to the specific reducer by yourself while mutlreducer can do that for you?

zincli commented 7 years ago

@yesmeck I'd prefer the syntax wrapAction() to use with redux-saga or other situation, for example:

function* foo() {
  yield put(wrapAction(barAction(), 'theKey'))
}

Sometimes we don't have to reuse the wrapped dispatch, say we have only one action need to wrapped. I think wrapAction() could be more elegant while meeting this situation.

Hope wrapAction() could be exported again.

yesmeck commented 7 years ago

@zincli PR's welcome.