| 1 |
"use strict"; |
| 2 |
var __values = (this && this.__values) || function(o) { |
| 3 |
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; |
| 4 |
if (m) return m.call(o); |
| 5 |
if (o && typeof o.length === "number") return { |
| 6 |
next: function () { |
| 7 |
if (o && i >= o.length) o = void 0; |
| 8 |
return { value: o && o[i++], done: !o }; |
| 9 |
} |
| 10 |
}; |
| 11 |
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); |
| 12 |
}; |
| 13 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 14 |
exports.windowToggle = void 0; |
| 15 |
var Subject_1 = require("../Subject"); |
| 16 |
var Subscription_1 = require("../Subscription"); |
| 17 |
var lift_1 = require("../util/lift"); |
| 18 |
var innerFrom_1 = require("../observable/innerFrom"); |
| 19 |
var OperatorSubscriber_1 = require("./OperatorSubscriber"); |
| 20 |
var noop_1 = require("../util/noop"); |
| 21 |
var arrRemove_1 = require("../util/arrRemove"); |
| 22 |
function windowToggle(openings, closingSelector) { |
| 23 |
return lift_1.operate(function (source, subscriber) { |
| 24 |
var windows = []; |
| 25 |
var handleError = function (err) { |
| 26 |
while (0 < windows.length) { |
| 27 |
windows.shift().error(err); |
| 28 |
} |
| 29 |
subscriber.error(err); |
| 30 |
}; |
| 31 |
innerFrom_1.innerFrom(openings).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (openValue) { |
| 32 |
var window = new Subject_1.Subject(); |
| 33 |
windows.push(window); |
| 34 |
var closingSubscription = new Subscription_1.Subscription(); |
| 35 |
var closeWindow = function () { |
| 36 |
arrRemove_1.arrRemove(windows, window); |
| 37 |
window.complete(); |
| 38 |
closingSubscription.unsubscribe(); |
| 39 |
}; |
| 40 |
var closingNotifier; |
| 41 |
try { |
| 42 |
closingNotifier = innerFrom_1.innerFrom(closingSelector(openValue)); |
| 43 |
} |
| 44 |
catch (err) { |
| 45 |
handleError(err); |
| 46 |
return; |
| 47 |
} |
| 48 |
subscriber.next(window.asObservable()); |
| 49 |
closingSubscription.add(closingNotifier.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, closeWindow, noop_1.noop, handleError))); |
| 50 |
}, noop_1.noop)); |
| 51 |
source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) { |
| 52 |
var e_1, _a; |
| 53 |
var windowsCopy = windows.slice(); |
| 54 |
try { |
| 55 |
for (var windowsCopy_1 = __values(windowsCopy), windowsCopy_1_1 = windowsCopy_1.next(); !windowsCopy_1_1.done; windowsCopy_1_1 = windowsCopy_1.next()) { |
| 56 |
var window_1 = windowsCopy_1_1.value; |
| 57 |
window_1.next(value); |
| 58 |
} |
| 59 |
} |
| 60 |
catch (e_1_1) { e_1 = { error: e_1_1 }; } |
| 61 |
finally { |
| 62 |
try { |
| 63 |
if (windowsCopy_1_1 && !windowsCopy_1_1.done && (_a = windowsCopy_1.return)) _a.call(windowsCopy_1); |
| 64 |
} |
| 65 |
finally { if (e_1) throw e_1.error; } |
| 66 |
} |
| 67 |
}, function () { |
| 68 |
while (0 < windows.length) { |
| 69 |
windows.shift().complete(); |
| 70 |
} |
| 71 |
subscriber.complete(); |
| 72 |
}, handleError, function () { |
| 73 |
while (0 < windows.length) { |
| 74 |
windows.shift().unsubscribe(); |
| 75 |
} |
| 76 |
})); |
| 77 |
}); |
| 78 |
} |
| 79 |
exports.windowToggle = windowToggle; |
| 80 |
//# sourceMappingURL=windowToggle.js.map |