您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 899B

123456789101112131415161718192021222324252627282930313233343536
  1. /* @flow */
  2. import _ from 'lodash';
  3. import MiddlewareRegistry from './MiddlewareRegistry';
  4. import PersistencyRegistry from './PersistencyRegistry';
  5. import { toState } from '../redux';
  6. /**
  7. * The delay that passes between the last state change and the state to be
  8. * persisted in the storage.
  9. */
  10. const PERSIST_DELAY = 2000;
  11. /**
  12. * A throttled function to avoid repetitive state persisting.
  13. */
  14. const throttledFunc = _.throttle(state => {
  15. PersistencyRegistry.persistState(state);
  16. }, PERSIST_DELAY);
  17. /**
  18. * A master MiddleWare to selectively persist state. Please use the
  19. * {@link persisterconfig.json} to set which subtrees of the Redux state
  20. * should be persisted.
  21. *
  22. * @param {Store} store - The redux store.
  23. * @returns {Function}
  24. */
  25. MiddlewareRegistry.register(store => next => action => {
  26. const result = next(action);
  27. throttledFunc(toState(store));
  28. return result;
  29. });