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 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // @flow
  2. import { APP_WILL_MOUNT } from '../app';
  3. import { ReducerRegistry, set } from '../base/redux';
  4. import { PersistenceRegistry } from '../base/storage';
  5. import {
  6. SET_CALENDAR_AUTHORIZATION,
  7. SET_CALENDAR_EVENTS
  8. } from './actionTypes';
  9. import { CALENDAR_ENABLED, DEFAULT_STATE } from './constants';
  10. /**
  11. * Constant for the Redux subtree of the calendar feature.
  12. *
  13. * NOTE: Please do not access this subtree directly outside of this feature.
  14. * This feature can be disabled (see {@code constants.js} for details), and in
  15. * that case, accessing this subtree directly will return undefined and will
  16. * need a bunch of repetitive type checks in other features. Use the
  17. * {@code getCalendarState} function instead, or make sure you take care of
  18. * those checks, or consider using the {@code CALENDAR_ENABLED} const to gate
  19. * features if needed.
  20. */
  21. const STORE_NAME = 'features/calendar-sync';
  22. /**
  23. * NOTE 1: For legacy purposes, read any {@code knownDomains} persisted by the
  24. * feature calendar-sync.
  25. *
  26. * NOTE 2: Never persist the authorization value as it's needed to remain a
  27. * runtime value to see if we need to re-request the calendar permission from
  28. * the user.
  29. */
  30. CALENDAR_ENABLED
  31. && PersistenceRegistry.register(STORE_NAME, {
  32. knownDomains: true
  33. });
  34. CALENDAR_ENABLED
  35. && ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
  36. switch (action.type) {
  37. case APP_WILL_MOUNT:
  38. // For legacy purposes, we've allowed the deserialization of
  39. // knownDomains. At this point, it should have already been
  40. // translated into the new state format (namely, base/known-domains)
  41. // and the app no longer needs it.
  42. if (typeof state.knownDomains !== 'undefined') {
  43. return set(state, 'knownDomains', undefined);
  44. }
  45. break;
  46. case SET_CALENDAR_AUTHORIZATION:
  47. return set(state, 'authorization', action.authorization);
  48. case SET_CALENDAR_EVENTS:
  49. return set(state, 'events', action.events);
  50. }
  51. return state;
  52. });