UNPKG

use-store-hooks

Version:

Create a redux-like store using hooks. Supports middleware

31 lines (28 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.invokeStore = invokeStore; exports["default"] = void 0; /** * @description Does a dry run to extract the initial state in case it was not defined * @param {Function} reducer a function which takes a current state and an action * @param {*} storeInit optional initial state * @param {Array} middlewares an array of redux friendly middleware * Redux friendly middleware consume dispatch, and getState, and has a minimal signature of * store => next => action => next(action) * @return {Object} container the reducer, a formal initialState and the middleware */ function invokeStore(reducer, storeInit) { var middlewares = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; // if the initial state is given, take it, // otherwise do a dry run var initialState = storeInit || reducer(undefined, {}); return { reducer: reducer, initialState: initialState, middlewares: middlewares }; } var _default = invokeStore; exports["default"] = _default;