Description
I have an application in which I split different pieces of functionality into Angular modules, and then use all the modules I need in a "core module" that actually bootstraps to the page:
let page = angular.module('CoreModule', ['Feature1', 'Feature2', 'Feature3']);
angular.bootstrap(document, ['CoreModule']);
All of these "feature modules" use ngRedux, so their config
stages all resemble the following:
module.config(($ngReduxProvider) => {
$ngReduxProvider.createStoreWith(reducer, [thunk]);
});
The problem is: createStoreWith
only allows a single reducer to be registered, meaning that you cannot register reducers from multiple "feature modules" with $ngReduxProvider
; in a example with 3 "feature modules", 2 will get smashed and only 1 will survive.
It would be nice if $ngReduxProvider
could register multiple reducers, and then the $get
method uses combineReducers
to combine all the registered reducers together and makes a store out of these combined reducers to create a single injectable instance of a $ngRedux
, thus preserving a single store. Usage may look like this:
module.config(($ngReduxProvider) => {
$ngReduxProvider.registerReducer(reducer, [thunk]);
});
This allows each "feature module" to be responsible for its own reducers. Without this, the "core module" has to import all possible reducers, combine them, and then register them with $ngReduxProvider
, breaking the single responsibility principle. Notice how each "feature module" should be able to register middleware with the $ngReduxProvider
.