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

Async reducers #106

Closed
wants to merge 3 commits into from
Closed

Async reducers #106

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 22, 2016

This is an attempt to solve the need to add or remove dinamically reducers to the store created with ng-redux.

The idea is very simple:

  • at config time we create the store with some "fixed" reducers that our application will always use
  • when the store is created, ng-redux adds to the store a new property called asyncReducers, which will store the reducers that we add or remove on execution time
  • we also add two methods to the created store: addReducer and removeReducer which adds or removes a reducer from the asyncReducers property, and replaces the store reducer with the combination of the "fixed" and "async" reducers.
  • addReducer gets two parameters: the name of the reducer to be appended and the reducer itself
  • removeReducer gets only one parameter: the name of the reducer to be removed

There's a "small" problem. To get this solution to work, we need to pass and object to createStore (which will be stored also on the store object and combined with the async reducers) and not with a function, because we can't combine reducers from combined ones (at least with the standard redux combineReducers function), and we need to combineReducers each time we add or remove a new reducer.

This could be used to solve the issue #75

Hope that this helps somebody, and you find it useful

@kaidjohnson
Copy link

This solution looks promising. It follows the recommendations discussed here reduxjs/redux#37 and demonstrated here https://gist.github.com/gaearon/0a2213881b5d53973514

@sachinnair90
Copy link

@wbuchwalter any plan to get this merged, I need this feature to be implemented in my app? Or is there an easier way around due to which this is on hold?

@AntJanus
Copy link
Collaborator

@sachinnair90 I'm gonna go ahead and close this branch since it's out of scope. ng-redux, in my opinion, is meant to provide as close to original redux functionality as possible (and react-redux, I suppose) while leveraging AngularJS's power.

As far as dynamically loading/async loading Reducers, you have a few options:

  1. Redux has a built-in replaceReducer API.
  2. Another user on this repo mentioned the ng-redux-injector which can do what you want it to do
  3. I wrote a quick enhancer on another PR Dynamic Load Reducers #121 I wrote a much bigger version of this as a wrapper for Redux but I can rewrite this as an enhancer if there's interest.

@AntJanus AntJanus closed this Sep 14, 2017
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

Successfully merging this pull request may close these issues.

4 participants