Skip to content
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

Question: Why not make dispatch available in transform? #33

Closed
hyperivo opened this issue Feb 4, 2017 · 3 comments
Closed

Question: Why not make dispatch available in transform? #33

hyperivo opened this issue Feb 4, 2017 · 3 comments
Labels

Comments

@hyperivo
Copy link

hyperivo commented Feb 4, 2017

Hi @jeffbski,

I have a use case where given an action I might modify it, reject it, or do nothing to it. However, when I reject it I want to dispatch a new action in order to have some information persisted to the state.

I notice that transform only has the next/reject methods available to it, is there a technical reason why dispatch is not there?

Thanks for your time,
Ivo

@hyperivo hyperivo changed the title Why not make dispatch available in transform? Question: Why not make dispatch available in transform? Feb 4, 2017
@KevinAst
Copy link

KevinAst commented Feb 4, 2017

Hello Ivo,

Jeff may have additional insight here, but you can optionally pass an action parameter to your reject() invocation.

There are different conditions, where the action can be:

  1. the original action
  2. one with a modified payload
  3. a completely new action (i.e. different action type)
  4. or no action parameter at all

I believe the third case will service your needs. If you call reject(newAction) redux-logic will basically kill the current action and re-dispatch the new one.

@hyperivo
Copy link
Author

hyperivo commented Feb 4, 2017

Hi @KevinAst,

Indeed 3. would solve my use case.

Thanks for your help :)

--Ivo

@jeffbski
Copy link
Owner

jeffbski commented Feb 4, 2017

Thanks for the question @hyperivo!

Kevin did a good job summarizing that. I appreciate it @KevinAst .

So yes, when you pass an action to accept or reject it will look at the type. If it is the same type it will internally call the middleware next handing it down to the rest of the middlewares and reducer. If it was a different type it will instead dispatch so that all necessary middleware will have a chance to see it. This behavior can be overridden with options but normally it is exactly what you want to happen (it also prevents the potential loops).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants