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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179 |
1
1
3
3
73
1
1
1
1
1
1
1
1
15
1
1
15
15
15
1
15
1
1
1
1
15
15
15
15
15
15
1
62
62
62
59
1
5
5
1
7
7
6
6
6
6
7
1
29
29
29
29
1
1
1
28
28
28
28
28
1
23
23
6
17
17
17
17
17
17
1
1
1
1
28
28
28
28
1
18
1
2
1
5
1
1
1
1
15
15
15
1
29
1
1
1
1
1 | 'use strict';
exports.__esModule = true;
exports['default'] = bufferToggle;
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 _Subscriber4 = require('../Subscriber');
var _Subscriber5 = _interopRequireDefault(_Subscriber4);
var _Subscription = require('../Subscription');
var _Subscription2 = _interopRequireDefault(_Subscription);
var _utilTryCatch = require('../util/tryCatch');
var _utilTryCatch2 = _interopRequireDefault(_utilTryCatch);
var _utilErrorObject = require('../util/errorObject');
/**
* buffers values from the source by opening the buffer via signals from an observable provided to `openings`, and closing
* and sending the buffers when an observable returned by the `closingSelector` emits.
* @param {Observable<O>} openings An observable of notifications to start new buffers
* @param {Function} an function, that takes the value emitted by the `openings` observable and returns an Observable, which,
* when it emits, signals that the associated buffer should be emitted and cleared.
* @returns {Observable<T[]>} an observable of arrays of buffered values.
*/
function bufferToggle(openings, closingSelector) {
return this.lift(new BufferToggleOperator(openings, closingSelector));
}
var BufferToggleOperator = (function () {
function BufferToggleOperator(openings, closingSelector) {
_classCallCheck(this, BufferToggleOperator);
this.openings = openings;
this.closingSelector = closingSelector;
}
BufferToggleOperator.prototype.call = function call(subscriber) {
return new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector);
};
return BufferToggleOperator;
})();
var BufferToggleSubscriber = (function (_Subscriber) {
_inherits(BufferToggleSubscriber, _Subscriber);
function BufferToggleSubscriber(destination, openings, closingSelector) {
_classCallCheck(this, BufferToggleSubscriber);
_Subscriber.call(this, destination);
this.openings = openings;
this.closingSelector = closingSelector;
this.contexts = [];
this.add(this.openings._subscribe(new BufferToggleOpeningsSubscriber(this)));
}
BufferToggleSubscriber.prototype._next = function _next(value) {
var contexts = this.contexts;
var len = contexts.length;
for (var i = 0; i < len; i++) {
contexts[i].buffer.push(value);
}
};
BufferToggleSubscriber.prototype._error = function _error(err) {
this.contexts = null;
this.destination.error(err);
};
BufferToggleSubscriber.prototype._complete = function _complete() {
var contexts = this.contexts;
while (contexts.length > 0) {
var context = contexts.shift();
this.destination.next(context.buffer);
context.subscription.unsubscribe();
context.buffer = null;
}
this.destination.complete();
};
BufferToggleSubscriber.prototype.openBuffer = function openBuffer(value) {
var closingSelector = this.closingSelector;
var contexts = this.contexts;
var closingNotifier = _utilTryCatch2['default'](closingSelector)(value);
if (closingNotifier === _utilErrorObject.errorObject) {
var err = closingNotifier.e;
this.contexts = null;
this.destination.error(err);
} else {
var context = {
buffer: [],
subscription: new _Subscription2['default']()
};
contexts.push(context);
var subscriber = new BufferClosingNotifierSubscriber(this, context);
var subscription = closingNotifier._subscribe(subscriber);
this.add(context.subscription.add(subscription));
}
};
BufferToggleSubscriber.prototype.closeBuffer = function closeBuffer(context) {
var contexts = this.contexts;
if (contexts === null) {
return;
}
var buffer = context.buffer;
var subscription = context.subscription;
this.destination.next(buffer);
contexts.splice(contexts.indexOf(context), 1);
this.remove(subscription);
subscription.unsubscribe();
};
return BufferToggleSubscriber;
})(_Subscriber5['default']);
var BufferClosingNotifierSubscriber = (function (_Subscriber2) {
_inherits(BufferClosingNotifierSubscriber, _Subscriber2);
function BufferClosingNotifierSubscriber(parent, context) {
_classCallCheck(this, BufferClosingNotifierSubscriber);
_Subscriber2.call(this, null);
this.parent = parent;
this.context = context;
}
BufferClosingNotifierSubscriber.prototype._next = function _next() {
this.parent.closeBuffer(this.context);
};
BufferClosingNotifierSubscriber.prototype._error = function _error(err) {
this.parent.error(err);
};
BufferClosingNotifierSubscriber.prototype._complete = function _complete() {
this.parent.closeBuffer(this.context);
};
return BufferClosingNotifierSubscriber;
})(_Subscriber5['default']);
var BufferToggleOpeningsSubscriber = (function (_Subscriber3) {
_inherits(BufferToggleOpeningsSubscriber, _Subscriber3);
function BufferToggleOpeningsSubscriber(parent) {
_classCallCheck(this, BufferToggleOpeningsSubscriber);
_Subscriber3.call(this, null);
this.parent = parent;
}
BufferToggleOpeningsSubscriber.prototype._next = function _next(value) {
this.parent.openBuffer(value);
};
BufferToggleOpeningsSubscriber.prototype._error = function _error(err) {
this.parent.error(err);
};
BufferToggleOpeningsSubscriber.prototype._complete = function _complete() {
// noop
};
return BufferToggleOpeningsSubscriber;
})(_Subscriber5['default']);
module.exports = exports['default']; |