UNPKG

@nteract/myths

Version:

A redux-observable framework for better locality of dependencies

46 lines 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeCreateMyth = void 0; const epics_1 = require("./epics"); const react_1 = require("./react"); const reducer_1 = require("./reducer"); exports.makeCreateMyth = (pkg, myths) => (name) => (definition) => { if (myths.hasOwnProperty(name)) { throw new Error(`Package "${pkg}" cannot have two myths with the same name ("${name}")`); } const mythWIP = { // Strings identifying this myth pkg, name, type: `${pkg}/${name}`, // for use in typeof expressions: props: undefined, state: undefined, action: undefined, }; // Function to create actions mythWIP.create = (payload) => ({ type: mythWIP.type, payload }); // Function to partial create actions mythWIP.with = (partial) => (payload) => ({ type: mythWIP.type, payload: Object.assign(Object.assign({}, partial), payload), }); // Epics to include into our rootEpic mythWIP.epics = epics_1.makeEpics(pkg, mythWIP, definition); // Is this action one of ours? mythWIP.appliesTo = (action) => action.type === mythWIP.type; // Reducer for our action mythWIP.reduce = reducer_1.makeReducer(definition.reduce, mythWIP.appliesTo); // Make a component that has access to our action mythWIP.createConnectedComponent = react_1.makeCreateConnectedComponent(mythWIP); const myth = mythWIP; myths[name] = myth; return myth; }; //# sourceMappingURL=myth.js.map