index.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. import {createStore, applyMiddleware} from 'redux';
  3. import {composeReducers} from 'redux-sac';
  4. import {effectsMiddleware} from 'redux-effex';
  5. export default () => {
  6. let reducers = [], effects = [], middlewares = [], initialState;
  7. function withReducers (..._reducers) {
  8. reducers.push(..._reducers);
  9. return this;
  10. }
  11. function withEffects (..._effects) {
  12. effects.push(..._effects);
  13. return this;
  14. }
  15. function withMiddlewares (..._middlewares) {
  16. middlewares.push(..._middlewares);
  17. return this;
  18. }
  19. function withInitializers (...initializers) {
  20. initialState = initializers.reduce((soFar, each) => each(soFar), initialState);
  21. return this;
  22. }
  23. function create () {
  24. return createStore(
  25. composeReducers(...reducers),
  26. initialState,
  27. applyMiddleware(...middlewares, effectsMiddleware(effects))
  28. );
  29. }
  30. return {withReducers, withMiddlewares, withEffects, withInitializers, create};
  31. }