@talend/react-cmf
Version:
A framework built on top of best react libraries
54 lines (51 loc) • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _registry = _interopRequireDefault(require("./registry"));
var _constant = _interopRequireDefault(require("./constant"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* return a function from the registry
* @param {object} context
* @param {string} id the id of the action creator
* @return {function}
*/
function get(context, id) {
const creator = context.registry[`${_constant.default.REGISTRY_ACTION_CREATOR_PREFIX}:${id}`];
if (!creator) {
// console.log('@@ registry', id, Object.keys(context.registry));
throw new Error(`actionCreator not found in the registry: ${id}`);
}
return creator;
}
/**
* register your action creator. The action creator is a function with
* the following arguments:
* - event which trigger this action
* - data attached to the action (could contains anything)
* - context of the current react app (could contains registry, getState, ...)
* @param {String} id
* @param {Function} actionCreator (event, data, context)
*/
function register(id, actionCreator, context) {
if (actionCreator === undefined) {
throw new Error(`CMF: you can't register an undefined value for the following action creator: '${id}'.
You may have an import error in your code. Check the stack trace and your bootstrap config imports.
https://github.com/Talend/ui/tree/master/packages/cmf/src/bootstrap.md`);
}
_registry.default.addToRegistry(`${_constant.default.REGISTRY_ACTION_CREATOR_PREFIX}:${id}`, actionCreator, context);
}
/**
* This function allow to register an object with some action creators
* @param {object} actionCreators map of action creators
* @param {object} context optional context to get the registry
*/
const registerMany = _registry.default.getRegisterMany(register);
var _default = exports.default = {
get,
register,
registerMany
};
//# sourceMappingURL=actionCreator.js.map