Skip to content

Instantly share code, notes, and snippets.

@kagiasoldaccount
Last active August 29, 2015 14:25
Show Gist options
  • Save kagiasoldaccount/e953b2fd9897a2ba4146 to your computer and use it in GitHub Desktop.
Save kagiasoldaccount/e953b2fd9897a2ba4146 to your computer and use it in GitHub Desktop.
redux 1.0.0-alpha store factory
import {createStore, combineReducers, applyMiddleware} from 'redux';
class StoreFactory {
constructor() {
this.reducers = {};
this.middlewares = [];
}
addReducers(reducers) {
this.reducers = {
...this.reducers,
...reducers
};
return this;
}
addMiddleWare(middlewares) {
this.middlewares = this.middlewares.concat(middlewares);
return this;
}
finish() {
let reducer = combineReducers(this.reducers);
let store = applyMiddleware(...this.middlewares)(createStore)(reducer);
return store;
}
}
export default StoreFactory;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment