UNPKG

redux-code

Version:

Redux helpers for actions and reducers

39 lines (38 loc) 1.11 kB
"use strict"; /* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.initReducer = exports.commonReducer = exports.commonActions = void 0; /** * Actions Mixin provides reset and update actions */ exports.commonActions = { /** * * Creates an action to reset the state */ reset: undefined, /** * * Creates an action to update the state with the given payload */ update: (payload) => payload, }; /** * * Creates a mixin for a reducer that adds the ability to reset and update the state * @param {actions} actions The actions to handle. * @param {initial} initial The initial state. */ const commonReducer = (actions, initial) => ({ [actions.reset.type]: () => initial, [actions.update.type]: (state, { payload }) => ({ ...state, ...payload }), }); exports.commonReducer = commonReducer; /** * Initial reducer. * Supports INIT action */ const initReducer = (actions) => ({ [actions.init.type]: (state) => ({ ...state, inited: true }), }); exports.initReducer = initReducer;