UNPKG

ayanami

Version:
44 lines (43 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOriginalFunctions = void 0; var rxjs_1 = require("rxjs"); var decorators_1 = require("../decorators"); var symbols_1 = require("../symbols"); var getOriginalFunctionNames = function (ayanami) { return ({ effects: decorators_1.getActionNames(symbols_1.effectSymbols, ayanami.constructor), reducers: decorators_1.getActionNames(symbols_1.reducerSymbols, ayanami.constructor), defineActions: decorators_1.getActionNames(symbols_1.defineActionSymbols, ayanami.constructor), immerReducers: decorators_1.getActionNames(symbols_1.immerReducerSymbols, ayanami.constructor), }); }; var transformDefineActions = function (actionNames) { var result = {}; actionNames.forEach(function (actionName) { var actions$ = new rxjs_1.Subject(); result[actionName] = { observable: actions$.asObservable(), next: function (params) { return actions$.next(params); }, }; }); return result; }; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types var getOriginalFunctions = function (ayanami) { var _a = getOriginalFunctionNames(ayanami), effects = _a.effects, reducers = _a.reducers, immerReducers = _a.immerReducers, defineActions = _a.defineActions; return { effects: effects.reduce(function (acc, method) { acc[method] = ayanami[method].bind(ayanami); return acc; }, {}), reducers: reducers.reduce(function (acc, method) { acc[method] = ayanami[method].bind(ayanami); return acc; }, {}), immerReducers: immerReducers.reduce(function (acc, method) { acc[method] = ayanami[method].bind(ayanami); return acc; }, {}), defineActions: transformDefineActions(defineActions), }; }; exports.getOriginalFunctions = getOriginalFunctions;