You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.js 917B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* @flow */
  2. import { MiddlewareRegistry } from '../base/redux';
  3. import {
  4. CLEAR_TOOLBOX_TIMEOUT,
  5. SET_TOOLBOX_TIMEOUT
  6. } from './actionTypes';
  7. /**
  8. * Middleware which intercepts Toolbox actions to handle changes to the
  9. * visibility timeout of the Toolbox.
  10. *
  11. * @param {Store} store - Redux store.
  12. * @returns {Function}
  13. */
  14. MiddlewareRegistry.register(store => next => action => {
  15. switch (action.type) {
  16. case CLEAR_TOOLBOX_TIMEOUT: {
  17. const { timeoutID } = store.getState()['features/toolbox'];
  18. clearTimeout(timeoutID);
  19. break;
  20. }
  21. case SET_TOOLBOX_TIMEOUT: {
  22. const { timeoutID } = store.getState()['features/toolbox'];
  23. const { handler, timeoutMS } = action;
  24. clearTimeout(timeoutID);
  25. const newTimeoutId = setTimeout(handler, timeoutMS);
  26. action.timeoutID = newTimeoutId;
  27. break;
  28. }
  29. }
  30. return next(action);
  31. });