mst-effect
Version:
Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
26 lines (25 loc) • 855 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runActions = exports.NOOP = exports.action = void 0;
const const_1 = require("../const");
function action(fn, ...params) {
return { [const_1.EFFECT_ACTION_IDENTITY]: () => fn(...params) };
}
exports.action = action;
exports.NOOP = action(() => { });
function runActions(actions) {
;
(Array.isArray(actions) ? actions : [actions]).forEach(runAction);
}
exports.runActions = runActions;
function runAction(action) {
if (isValidAction(action)) {
action[const_1.EFFECT_ACTION_IDENTITY]();
}
else {
console.warn(`[mst-effect]: ${String(action)} is not a valid EffectActions`);
}
}
function isValidAction(action) {
return (action && typeof action === 'object' && typeof action[const_1.EFFECT_ACTION_IDENTITY] === 'function');
}