@talend/react-cmf
Version:
A framework built on top of best react libraries
78 lines (72 loc) • 2.76 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addComponentState = exports.COMPONENT_REMOVE_STATE = exports.COMPONENT_MERGE_STATE = exports.COMPONENT_ADD_STATE = void 0;
exports.addState = addState;
exports.removeState = exports.removeComponentState = exports.mergeState = exports.mergeComponentState = void 0;
var _constant = _interopRequireDefault(require("../constant"));
var _lodash = require("lodash");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* @module react-cmf/lib/actions/componentsActions
*/
// keep backward compatibility
const {
COMPONENT_ADD_STATE,
COMPONENT_MERGE_STATE,
COMPONENT_REMOVE_STATE
} = _constant.default;
/**
* 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
*/
exports.COMPONENT_REMOVE_STATE = COMPONENT_REMOVE_STATE;
exports.COMPONENT_MERGE_STATE = COMPONENT_MERGE_STATE;
exports.COMPONENT_ADD_STATE = COMPONENT_ADD_STATE;
function addState(componentName, key, initialComponentState) {
return {
type: _constant.default.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
*/
const mergeState = exports.mergeState = (0, _lodash.curry)((componentName, key, componentState) => ({
type: _constant.default.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
*/
const removeState = exports.removeState = (0, _lodash.curry)((componentName, key) => ({
type: _constant.default.COMPONENT_REMOVE_STATE,
componentName,
key
}));
// backward compatbility
const addComponentState = exports.addComponentState = addState;
const removeComponentState = exports.removeComponentState = removeState;
const mergeComponentState = exports.mergeComponentState = mergeState;
//# sourceMappingURL=componentsActions.js.map
;