Last active
August 29, 2015 14:25
-
-
Save kagiasoldaccount/e953b2fd9897a2ba4146 to your computer and use it in GitHub Desktop.
redux 1.0.0-alpha store factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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