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

redux-thunk compatibility #9

Closed
jmarceli opened this issue Oct 28, 2015 · 11 comments
Closed

redux-thunk compatibility #9

jmarceli opened this issue Oct 28, 2015 · 11 comments

Comments

@jmarceli
Copy link

For regular redux reducer action I can return a function. Example:

export function fetchDataIfNeeded() {
  return (dispatch, getState) => {
    if (shouldFetchData(getState(), storeName)) {
      return dispatch(fetchData())
    } else {
      return Promise.resolve()
    }
  }
}

Is it possible also with multireducer? How?

I've tried code above but with no luck. Returned function was never executed.

@jmarceli jmarceli changed the title return (dispatch, getState) redux-thunk compatibility Oct 28, 2015
@adailey14
Copy link

I just created a fork of this project that does things a bit differently and allows for use with thunk middleware (but you have to manually pass in the multireducerKey when using thunks so not amazing). It also changes the semantics of the project a bit to be closer to connect() and bindActionCreators(), and allows for multiple mountpoints. I needed this for a project I'm working on. Here is the link:

https://github.com/adailey14/multireducer

@erikras please take a look and let me know if you'd like me to make a pull request or anything. I haven't contributed to much open source on github so you'll have to let me know exactly how to do that. This would break backwards-compatability for the repo though so maybe you won't want to.

@jmarceli
Copy link
Author

jmarceli commented Dec 1, 2015

Looks nice. I manage to solve my problem without multi reducer (by making reducer class) but your solution is much cleaner than mine. I'll probably try to use it in my next project.

@adailey14
Copy link

Thanks @jmarceli. I just did a bit of a rewrite and figured out how to make thunks work with no extra effort, which is so much better. The trick was taking over dispatch so that it wraps any dispatched actions with the multireducerKey, and wraps any 'thunk' action creators inside another thunk that passes them the modified dispatch.

@erikras let me know when you have a chance to check it out - we could probably make it backwards compatible without too much effort and merge it back into this repo if you want to.

@jsdmc
Copy link
Contributor

jsdmc commented Dec 29, 2015

multireducer definitely needs redux-thunk support. It's common case to use thunk actions in redux-apps, so it should be possible to use them in actions that are handled by multireducer

@Elyx0
Copy link

Elyx0 commented Jan 18, 2016

Same issue here, did @adailey14 do a PR for this ?

@adailey14
Copy link

Sorry, i never did a PR. I am using that project fork for a personal project, and I think it probably diverged too much from this to do a clean PR. Feel free to jump into that code and put together a PR if you're so inclined!

@jsdmc
Copy link
Contributor

jsdmc commented Jan 20, 2016

Hi guys.
@adailey14 I took your changes and added some mine as well.
@erikras I also used some code from redux-form (wrapMapStateToProps, wrapMapDispatchToProps)
https://github.com/jsdmc/multireducer

Can you pls check example of usage (http://localhost:3000/countersPage) and we can discuss API
https://github.com/jsdmc/react-redux-router-crud-boilerplate/tree/multireducer

Cheers

@netpoetica
Copy link

I hate a be a plus-oner, but this would be incredibly useful. Setting this up with redux-thunk or redux-actions as middleware is essential

@erikras
Copy link
Owner

erikras commented Jan 21, 2016

I'd be willing to accept a PR, but I don't have the time to code it myself.

@jsdmc
Copy link
Contributor

jsdmc commented Jan 26, 2016

submitted PR #103

@adailey14
Copy link

👍

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

No branches or pull requests

6 participants