typedux
Version:
Slightly adjusted Redux (awesome by default) for TS
88 lines • 3.28 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "../util"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultLeafReducer = void 0;
var util_1 = require("../util");
/**
* Leaf reducer
*/
var DefaultLeafReducer = /** @class */ (function () {
function DefaultLeafReducer(_leaf, _stateType) {
this._leaf = _leaf;
this._stateType = _stateType;
}
/**
* Inflate from js
*
* @param stateType
* @param o
* @returns {any}
*/
DefaultLeafReducer.stateFromJS = function (stateType, o) {
var fromJS = stateType.fromJS;
return (fromJS) ? fromJS(o) : new stateType(o);
};
/**
* Create a new leaf reducer
*
* @param leaf
* @param stateType
* @returns {AnonLeafReducer}
*/
DefaultLeafReducer.create = function (leaf, stateType) {
var AnonLeafReducer = /** @class */ (function (_super) {
__extends(AnonLeafReducer, _super);
function AnonLeafReducer() {
return _super.call(this, leaf, stateType) || this;
}
AnonLeafReducer.prototype.defaultState = function (o) {
return stateType.fromJS(o);
};
return AnonLeafReducer;
}(DefaultLeafReducer));
return new AnonLeafReducer();
};
DefaultLeafReducer.prototype.stateType = function () {
return this._stateType;
};
DefaultLeafReducer.prototype.leaf = function () {
return this._leaf;
};
DefaultLeafReducer.prototype.defaultState = function (o) {
return new this._stateType(o);
};
DefaultLeafReducer.prototype.equals = function (o) {
var otherLeaf = util_1.isString(o) ? o :
(o && util_1.isFunction(o.leaf)) ? o.leaf() :
null;
return (otherLeaf && otherLeaf === o.leaf());
};
DefaultLeafReducer.prototype.valueOf = function () {
return this.leaf();
};
return DefaultLeafReducer;
}());
exports.DefaultLeafReducer = DefaultLeafReducer;
});
//# sourceMappingURL=DefaultLeafReducer.js.map