1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | 1 1 3 1 16 1 1 1 1 1 1 1 8 8 8 1 1 8 8 8 8 1 8 1 1 1 1 8 8 8 8 8 8 8 7 7 7 7 7 1 1 1 1 29 29 29 28 1 2 2 1 2 1 4 4 5 4 1 18 18 18 18 1 10 10 10 1 1 2 2 2 2 2 2 2 1 8 8 8 8 8 8 8 8 8 8 8 1 10 10 10 10 6 10 1 | 'use strict'; exports.__esModule = true; exports['default'] = windowTime; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _inherits(subClass, superClass) { Iif (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var _Subscriber2 = require('../Subscriber'); var _Subscriber3 = _interopRequireDefault(_Subscriber2); var _Subject = require('../Subject'); var _Subject2 = _interopRequireDefault(_Subject); var _schedulersNextTick = require('../schedulers/nextTick'); var _schedulersNextTick2 = _interopRequireDefault(_schedulersNextTick); function windowTime(windowTimeSpan) { var windowCreationInterval = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; var scheduler = arguments.length <= 2 || arguments[2] === undefined ? _schedulersNextTick2['default'] : arguments[2]; return this.lift(new WindowTimeOperator(windowTimeSpan, windowCreationInterval, scheduler)); } var WindowTimeOperator = (function () { function WindowTimeOperator(windowTimeSpan, windowCreationInterval, scheduler) { _classCallCheck(this, WindowTimeOperator); this.windowTimeSpan = windowTimeSpan; this.windowCreationInterval = windowCreationInterval; this.scheduler = scheduler; } WindowTimeOperator.prototype.call = function call(subscriber) { return new WindowTimeSubscriber(subscriber, this.windowTimeSpan, this.windowCreationInterval, this.scheduler); }; return WindowTimeOperator; })(); var WindowTimeSubscriber = (function (_Subscriber) { _inherits(WindowTimeSubscriber, _Subscriber); function WindowTimeSubscriber(destination, windowTimeSpan, windowCreationInterval, scheduler) { _classCallCheck(this, WindowTimeSubscriber); _Subscriber.call(this, destination); this.windowTimeSpan = windowTimeSpan; this.windowCreationInterval = windowCreationInterval; this.scheduler = scheduler; this.windows = []; if (windowCreationInterval !== null && windowCreationInterval >= 0) { var _window = this.openWindow(); var closeState = { subscriber: this, window: _window, context: null }; var creationState = { windowTimeSpan: windowTimeSpan, windowCreationInterval: windowCreationInterval, subscriber: this, scheduler: scheduler }; this.add(scheduler.schedule(dispatchWindowClose, windowTimeSpan, closeState)); this.add(scheduler.schedule(dispatchWindowCreation, windowCreationInterval, creationState)); } else { var _window2 = this.openWindow(); var timeSpanOnlyState = { subscriber: this, window: _window2, windowTimeSpan: windowTimeSpan }; this.add(scheduler.schedule(dispatchWindowTimeSpanOnly, windowTimeSpan, timeSpanOnlyState)); } } WindowTimeSubscriber.prototype._next = function _next(value) { var windows = this.windows; var len = windows.length; for (var i = 0; i < len; i++) { windows[i].next(value); } }; WindowTimeSubscriber.prototype._error = function _error(err) { var windows = this.windows; while (windows.length > 0) { windows.shift().error(err); } this.destination.error(err); }; WindowTimeSubscriber.prototype._complete = function _complete() { var windows = this.windows; while (windows.length > 0) { windows.shift().complete(); } this.destination.complete(); }; WindowTimeSubscriber.prototype.openWindow = function openWindow() { var window = new _Subject2['default'](); this.windows.push(window); this.destination.next(window); return window; }; WindowTimeSubscriber.prototype.closeWindow = function closeWindow(window) { window.complete(); var windows = this.windows; windows.splice(windows.indexOf(window), 1); }; return WindowTimeSubscriber; })(_Subscriber3['default']); function dispatchWindowTimeSpanOnly(state) { var subscriber = state.subscriber; var windowTimeSpan = state.windowTimeSpan; var window = state.window; Eif (window) { window.complete(); } state.window = subscriber.openWindow(); this.schedule(state, windowTimeSpan); } function dispatchWindowCreation(state) { var windowTimeSpan = state.windowTimeSpan; var subscriber = state.subscriber; var scheduler = state.scheduler; var windowCreationInterval = state.windowCreationInterval; var window = subscriber.openWindow(); var action = this; var context = { action: action, subscription: null }; var timeSpanState = { subscriber: subscriber, window: window, context: context }; context.subscription = scheduler.schedule(dispatchWindowClose, windowTimeSpan, timeSpanState); action.add(context.subscription); action.schedule(state, windowCreationInterval); } function dispatchWindowClose(_ref) { var subscriber = _ref.subscriber; var window = _ref.window; var context = _ref.context; if (context && context.action && context.subscription) { context.action.remove(context.subscription); } subscriber.closeWindow(window); } //# sourceMappingURL=windowTime.js.map module.exports = exports['default']; //# sourceMappingURL=windowTime.js.map |