Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

reducer.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // @flow
  2. import { APP_WILL_MOUNT } from '../../app';
  3. import { ReducerRegistry } from '../redux';
  4. import { PersistenceRegistry } from '../storage';
  5. import { ADD_KNOWN_DOMAINS } from './actionTypes';
  6. /**
  7. * The default list of domains known to the feature base/known-domains.
  8. * Generally, it should be in sync with the domains associated with the app
  9. * through its manifest (in other words, Universal Links, deep linking). Anyway,
  10. * we need a hardcoded list because it has proven impossible to programmatically
  11. * read the information out of the app's manifests: App Store strips the
  12. * associated domains manifest out of the app so it's never downloaded on the
  13. * client and we did not spend a lot of effort to read the associated domains
  14. * out of the Andorid manifest.
  15. */
  16. export const DEFAULT_STATE = [
  17. 'beta.hipchat.me',
  18. 'beta.meet.jit.si',
  19. 'chaos.hipchat.me',
  20. 'enso.me',
  21. 'hipchat.me',
  22. 'meet.jit.si'
  23. ];
  24. const STORE_NAME = 'features/base/known-domains';
  25. PersistenceRegistry.register(STORE_NAME);
  26. ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
  27. switch (action.type) {
  28. case ADD_KNOWN_DOMAINS:
  29. return _addKnownDomains(state, action.knownDomains);
  30. case APP_WILL_MOUNT:
  31. // In case persistence has deserialized a weird redux state:
  32. return _addKnownDomains(state, DEFAULT_STATE);
  33. default:
  34. return state;
  35. }
  36. });
  37. /**
  38. * Adds an array of known domains to the list of domains known to the feature
  39. * base/known-domains.
  40. *
  41. * @param {Object} state - The redux state.
  42. * @param {Array<string>} knownDomains - The array of known domains to add to
  43. * the list of domains known to the feature base/known-domains.
  44. * @private
  45. * @returns {Object} The next redux state.
  46. */
  47. function _addKnownDomains(state, knownDomains) {
  48. // In case persistence has deserialized a weird redux state:
  49. let nextState = Array.isArray(state) ? state : [];
  50. if (Array.isArray(knownDomains)) {
  51. nextState = Array.from(state);
  52. for (let knownDomain of knownDomains) {
  53. knownDomain = knownDomain.toLowerCase();
  54. nextState.indexOf(knownDomain) === -1
  55. && nextState.push(knownDomain);
  56. }
  57. }
  58. return nextState;
  59. }