@talend/react-cmf
Version:
A framework built on top of best react libraries
67 lines (61 loc) • 1.99 kB
JavaScript
/**
* @module react-cmf/lib/actions/componentsActions
*/
import CONSTANTS from '../constant';
// keep backward compatibility
import { curry } from "lodash";
export const {
COMPONENT_ADD_STATE,
COMPONENT_MERGE_STATE,
COMPONENT_REMOVE_STATE
} = CONSTANTS;
/**
* add a new component state with optional initialComponentState to the store
*
* @param {string} componentName : name of the component
* @param {string} key : identifier of state used by this component
* @param {object} initialComponentState : initial state of the component if required
*
* @throw if a component with this componentName associated to this key already exist
*/
export function addState(componentName, key, initialComponentState) {
return {
type: CONSTANTS.COMPONENT_ADD_STATE,
componentName,
key,
initialComponentState
};
}
/**
* Merge new component state into actual component state in the store
* curried function
* @param {string} componentName : name of the component
* @param {string} key : identifier of state used by this component
* @param {object} componentState : initial state of the component if required
*
* @throw if no componentName associated with this collectionId exist
*/
export const mergeState = curry((componentName, key, componentState) => ({
type: CONSTANTS.COMPONENT_MERGE_STATE,
componentName,
key,
componentState
}));
/**
* Remove component state from the store
* curried function
* @param {string} componentName : name of the component
* @param {string} key : identifier of collection used by the component
*
* @throw if no componentName associated with this collectionId exist
*/
export const removeState = curry((componentName, key) => ({
type: CONSTANTS.COMPONENT_REMOVE_STATE,
componentName,
key
}));
// backward compatbility
export const addComponentState = addState;
export const removeComponentState = removeState;
export const mergeComponentState = mergeState;
//# sourceMappingURL=componentsActions.js.map