Source: actions/componentsActions.js

  1. /**
  2. * @module react-cmf/lib/actions/componentsActions
  3. */
  4. import curry from 'lodash/curry';
  5. import CONSTANTS from '../constant';
  6. // keep backward compatibility
  7. export const { COMPONENT_ADD_STATE, COMPONENT_MERGE_STATE, COMPONENT_REMOVE_STATE } = CONSTANTS;
  8. /**
  9. * add a new component state with optional initialComponentState to the store
  10. *
  11. * @param {string} componentName : name of the component
  12. * @param {string} key : identifier of state used by this component
  13. * @param {object} initialComponentState : initial state of the component if required
  14. *
  15. * @throw if a component with this componentName associated to this key already exist
  16. */
  17. export function addState(componentName, key, initialComponentState) {
  18. return {
  19. type: CONSTANTS.COMPONENT_ADD_STATE,
  20. componentName,
  21. key,
  22. initialComponentState,
  23. };
  24. }
  25. /**
  26. * Merge new component state into actual component state in the store
  27. * curried function
  28. * @param {string} componentName : name of the component
  29. * @param {string} key : identifier of state used by this component
  30. * @param {object} componentState : initial state of the component if required
  31. *
  32. * @throw if no componentName associated with this collectionId exist
  33. */
  34. export const mergeState = curry((componentName, key, componentState) => ({
  35. type: CONSTANTS.COMPONENT_MERGE_STATE,
  36. componentName,
  37. key,
  38. componentState,
  39. }));
  40. /**
  41. * Remove component state from the store
  42. * curried function
  43. * @param {string} componentName : name of the component
  44. * @param {string} key : identifier of collection used by the component
  45. *
  46. * @throw if no componentName associated with this collectionId exist
  47. */
  48. export const removeState = curry((componentName, key) => ({
  49. type: CONSTANTS.COMPONENT_REMOVE_STATE,
  50. componentName,
  51. key,
  52. }));
  53. // backward compatbility
  54. export const addComponentState = addState;
  55. export const removeComponentState = removeState;
  56. export const mergeComponentState = mergeState;