UNPKG

dreamstate

Version:

Store management library based on react context and observers

27 lines (24 loc) 1.2 kB
import { DreamstateError } from '../core/error/DreamstateError.js'; import { ActionsStore } from '../core/storing/ActionsStore.js'; import { EDreamstateErrorCode } from '../types/error.js'; import { isObject } from './typechecking.js'; /** * Creates an actions store, which is an object containing readonly method links representing actions. * The intention is to provide a container that is visually and programmatically distinguishable as * a storage of actions. * * Every call to 'setContext' will perform a comparison of the current 'context' before updating, * excluding the actions object, as it is expected to be immutable and consistent. * * @template T The type of actions object. * @param {T} actions - An object containing a set of mutation operations (actions). * @returns {Readonly<T>} An instance of an ActionsStore class containing the supplied actions. */ function createActions(actions) { if (isObject(actions)) { return new ActionsStore(actions); } else { throw new DreamstateError(EDreamstateErrorCode.INCORRECT_PARAMETER, "Actions store should be initialized with an object, got '".concat(typeof actions, "' instead.")); } } export { createActions };