UNPKG

rxdeep

Version:
42 lines 1.99 kB
"use strict"; 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 (b.hasOwnProperty(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 __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.persistent = exports.PersistentState = void 0; var rxjs_1 = require("rxjs"); var operators_1 = require("rxjs/operators"); var state_1 = require("./state"); var PersistentState = /** @class */ (function (_super) { __extends(PersistentState, _super); function PersistentState(state, storage, transform) { var _this = _super.call(this, state.value, rxjs_1.merge(state.downstream, state.downstream.pipe(operators_1.filter(function (change) { return _this._received !== change.value; }), transform || (function (_) { return _; }), operators_1.tap(function (change) { _this._received = change.value; storage.save(change.value); }), operators_1.filter(function () { return false; })), storage.load().pipe(operators_1.tap(function (value) { _this._received = value; _this.next(value); }), operators_1.filter(function () { return false; }))), state.upstream) || this; _this.state = state; _this.storage = storage; _this.transform = transform; return _this; } return PersistentState; }(state_1.State)); exports.PersistentState = PersistentState; function persistent(state, storage) { return new PersistentState(state, storage); } exports.persistent = persistent; //# sourceMappingURL=persistent.js.map