UNPKG

@cycle/state

Version:

Wraps your Cycle.js main function with reducer-driven state management

139 lines 3.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var xstream_1 = require("xstream"); var PickCombineListener = /** @class */ (function () { function PickCombineListener(key, out, p, ins) { this.key = key; this.out = out; this.p = p; this.val = xstream_1.NO; this.ins = ins; } PickCombineListener.prototype._n = function (t) { var p = this.p, out = this.out; this.val = t; if (out === null) { return; } this.p.up(); }; PickCombineListener.prototype._e = function (err) { var out = this.out; if (out === null) { return; } out._e(err); }; PickCombineListener.prototype._c = function () { }; return PickCombineListener; }()); var PickCombine = /** @class */ (function () { function PickCombine(sel, ins) { this.type = 'combine'; this.ins = ins; this.sel = sel; this.out = null; this.ils = new Map(); this.inst = null; } PickCombine.prototype._start = function (out) { this.out = out; this.ins._add(this); }; PickCombine.prototype._stop = function () { this.ins._remove(this); var ils = this.ils; ils.forEach(function (il) { il.ins._remove(il); il.ins = null; il.out = null; il.val = null; }); ils.clear(); this.out = null; this.ils = new Map(); this.inst = null; }; PickCombine.prototype.up = function () { var arr = this.inst.arr; var n = arr.length; var ils = this.ils; var outArr = Array(n); for (var i = 0; i < n; ++i) { var sinks = arr[i]; var key = sinks._key; if (!ils.has(key)) { return; } var val = ils.get(key).val; if (val === xstream_1.NO) { return; } outArr[i] = val; } this.out._n(outArr); }; PickCombine.prototype._n = function (inst) { this.inst = inst; var arrSinks = inst.arr; var ils = this.ils; var out = this.out; var sel = this.sel; var dict = inst.dict; var n = arrSinks.length; // remove var removed = false; ils.forEach(function (il, key) { if (!dict.has(key)) { il.ins._remove(il); il.ins = null; il.out = null; il.val = null; ils.delete(key); removed = true; } }); if (n === 0) { out._n([]); return; } // add for (var i = 0; i < n; ++i) { var sinks = arrSinks[i]; var key = sinks._key; if (!sinks[sel]) { throw new Error('pickCombine found an undefined child sink stream'); } var sink = xstream_1.default.fromObservable(sinks[sel]); if (!ils.has(key)) { ils.set(key, new PickCombineListener(key, out, this, sink)); sink._add(ils.get(key)); } } if (removed) { this.up(); } }; PickCombine.prototype._e = function (e) { var out = this.out; if (out === null) { return; } out._e(e); }; PickCombine.prototype._c = function () { var out = this.out; if (out === null) { return; } out._c(); }; return PickCombine; }()); function pickCombine(selector) { return function pickCombineOperator(inst$) { return new xstream_1.Stream(new PickCombine(selector, inst$)); }; } exports.pickCombine = pickCombine; //# sourceMappingURL=pickCombine.js.map