UNPKG

typedux

Version:

Slightly adjusted Redux (awesome by default) for TS

58 lines 1.38 kB
import { isString, isFunction } from '../util'; /** * Leaf reducer */ export class DefaultLeafReducer { constructor(_leaf, _stateType) { this._leaf = _leaf; this._stateType = _stateType; } /** * Inflate from js * * @param stateType * @param o * @returns {any} */ static stateFromJS(stateType, o) { const { fromJS } = stateType; return (fromJS) ? fromJS(o) : new stateType(o); } /** * Create a new leaf reducer * * @param leaf * @param stateType * @returns {AnonLeafReducer} */ static create(leaf, stateType) { class AnonLeafReducer extends DefaultLeafReducer { constructor() { super(leaf, stateType); } defaultState(o) { return stateType.fromJS(o); } } return new AnonLeafReducer(); } stateType() { return this._stateType; } leaf() { return this._leaf; } defaultState(o) { return new this._stateType(o); } equals(o) { const otherLeaf = isString(o) ? o : (o && isFunction(o.leaf)) ? o.leaf() : null; return (otherLeaf && otherLeaf === o.leaf()); } valueOf() { return this.leaf(); } } //# sourceMappingURL=DefaultLeafReducer.js.map