store.js 640 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { combineReducers, createStore } from 'redux';
  2. export class StoreWrapper {
  3. constructor() {
  4. this._store = null;
  5. this._reducers = {};
  6. this._initialState = {};
  7. }
  8. addReducer(name, reducer, initialState) {
  9. this._reducers[name] = reducer;
  10. this._initialState[name] = initialState;
  11. }
  12. init() {
  13. this._store = createStore(
  14. combineReducers(this._reducers), this._initialState);
  15. }
  16. getStore() {
  17. return this._store;
  18. }
  19. // Store API
  20. getState() {
  21. return this._store.getState();
  22. }
  23. dispatch(action) {
  24. return this._store.dispatch(action);
  25. }
  26. }
  27. export default new StoreWrapper();