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.

reducer.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // @flow
  2. import { ReducerRegistry, set } from '../redux';
  3. import { CLIENT_RESIZED, SET_ASPECT_RATIO, SET_CONTEXT_MENU_OPEN, SET_REDUCED_UI } from './actionTypes';
  4. import { ASPECT_RATIO_NARROW } from './constants';
  5. const {
  6. innerHeight = 0,
  7. innerWidth = 0
  8. } = window;
  9. /**
  10. * The default/initial redux state of the feature base/responsive-ui.
  11. */
  12. const DEFAULT_STATE = {
  13. aspectRatio: ASPECT_RATIO_NARROW,
  14. clientHeight: innerHeight,
  15. clientWidth: innerWidth,
  16. reducedUI: false,
  17. contextMenuOpened: false
  18. };
  19. ReducerRegistry.register('features/base/responsive-ui', (state = DEFAULT_STATE, action) => {
  20. switch (action.type) {
  21. case CLIENT_RESIZED: {
  22. return {
  23. ...state,
  24. clientWidth: action.clientWidth,
  25. clientHeight: action.clientHeight
  26. };
  27. }
  28. case SET_ASPECT_RATIO:
  29. return set(state, 'aspectRatio', action.aspectRatio);
  30. case SET_REDUCED_UI:
  31. return set(state, 'reducedUI', action.reducedUI);
  32. case SET_CONTEXT_MENU_OPEN:
  33. return set(state, 'contextMenuOpened', action.isOpen);
  34. }
  35. return state;
  36. });