| 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264 |
1
5
2
197
1
1
1
1
1
1
1
1
1
1
1
1
1
1
48
48
1
48
1
1
1
1
1
48
48
48
48
48
48
48
48
1
101
101
101
10
91
2
89
1
48
48
48
48
48
101
101
89
12
1
10
10
1
1
160
160
160
160
311
311
89
71
71
71
154
154
154
7
154
154
71
71
34
34
2
32
37
71
6
1
1
1
1
2
2
2
1
7
1
7
7
7
1
7
7
1
1
1
10
10
10
10
10
1
1
6
6
6
1
7
1
6
1
1
1
1
89
89
89
89
89
89
89
89
1
1
141
141
141
1
297
1
141
1
35
10
10
25
1
160
160
1
89
1
| 'use strict';
exports.__esModule = true;
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 _utilTryCatch = require('../util/tryCatch');
var _utilTryCatch2 = _interopRequireDefault(_utilTryCatch);
var _utilErrorObject = require('../util/errorObject');
var _OuterSubscriber2 = require('../OuterSubscriber');
var _OuterSubscriber3 = _interopRequireDefault(_OuterSubscriber2);
var _utilSubscribeToResult = require('../util/subscribeToResult');
var _utilSubscribeToResult2 = _interopRequireDefault(_utilSubscribeToResult);
var _utilSymbol_iterator = require('../util/Symbol_iterator');
var _utilSymbol_iterator2 = _interopRequireDefault(_utilSymbol_iterator);
var isArray = Array.isArray;
var ZipOperator = (function () {
function ZipOperator(project) {
_classCallCheck(this, ZipOperator);
this.project = project;
}
ZipOperator.prototype.call = function call(subscriber) {
return new ZipSubscriber(subscriber, this.project);
};
return ZipOperator;
})();
exports.ZipOperator = ZipOperator;
var ZipSubscriber = (function (_Subscriber) {
_inherits(ZipSubscriber, _Subscriber);
function ZipSubscriber(destination, project) {
var values = arguments.length <= 2 || arguments[2] === undefined ? Object.create(null) : arguments[2];
_classCallCheck(this, ZipSubscriber);
_Subscriber.call(this, destination);
this.index = 0;
this.iterators = [];
this.active = 0;
this.project = typeof project === 'function' ? project : null;
this.values = values;
}
ZipSubscriber.prototype._next = function _next(value) {
var iterators = this.iterators;
var index = this.index++;
if (isArray(value)) {
iterators.push(new StaticArrayIterator(value));
} else if (typeof value[_utilSymbol_iterator2['default']] === 'function') {
iterators.push(new StaticIterator(value[_utilSymbol_iterator2['default']]()));
} else {
iterators.push(new ZipBufferIterator(this.destination, this, value, index));
}
};
ZipSubscriber.prototype._complete = function _complete() {
var values = this.values;
var iterators = this.iterators;
var len = iterators.length;
this.active = len;
for (var i = 0; i < len; i++) {
var iterator = iterators[i];
if (iterator.stillUnsubscribed) {
iterator.subscribe(iterator, i);
} else {
this.active--; // not an observable
}
}
};
ZipSubscriber.prototype.notifyInactive = function notifyInactive() {
this.active--;
if (this.active === 0) {
this.destination.complete();
}
};
ZipSubscriber.prototype.checkIterators = function checkIterators() {
var iterators = this.iterators;
var len = iterators.length;
var destination = this.destination;
// abort if not all of them have values
for (var i = 0; i < len; i++) {
var iterator = iterators[i];
if (typeof iterator.hasValue === 'function' && !iterator.hasValue()) {
return;
}
}
var shouldComplete = false;
var args = [];
for (var i = 0; i < len; i++) {
var iterator = iterators[i];
var result = iterator.next();
// check to see if it's completed now that you've gotten
// the next value.
if (iterator.hasCompleted()) {
shouldComplete = true;
}
Iif (result.done) {
destination.complete();
return;
}
args.push(result.value);
}
var project = this.project;
if (project) {
var result = _utilTryCatch2['default'](project).apply(this, args);
if (result === _utilErrorObject.errorObject) {
destination.error(_utilErrorObject.errorObject.e);
} else {
destination.next(result);
}
} else {
destination.next(args);
}
if (shouldComplete) {
destination.complete();
}
};
return ZipSubscriber;
})(_Subscriber3['default']);
exports.ZipSubscriber = ZipSubscriber;
var StaticIterator = (function () {
function StaticIterator(iterator) {
_classCallCheck(this, StaticIterator);
this.iterator = iterator;
this.nextResult = iterator.next();
}
StaticIterator.prototype.hasValue = function hasValue() {
return true;
};
StaticIterator.prototype.next = function next() {
var result = this.nextResult;
this.nextResult = this.iterator.next();
return result;
};
StaticIterator.prototype.hasCompleted = function hasCompleted() {
var nextResult = this.nextResult;
return nextResult && nextResult.done;
};
return StaticIterator;
})();
var StaticArrayIterator = (function () {
function StaticArrayIterator(array) {
_classCallCheck(this, StaticArrayIterator);
this.array = array;
this.index = 0;
this.length = 0;
this.length = array.length;
}
StaticArrayIterator.prototype[_utilSymbol_iterator2['default']] = function () {
return this;
};
StaticArrayIterator.prototype.next = function next(value) {
var i = this.index++;
var array = this.array;
return i < this.length ? { value: array[i], done: false } : { done: true };
};
StaticArrayIterator.prototype.hasValue = function hasValue() {
return this.array.length > this.index;
};
StaticArrayIterator.prototype.hasCompleted = function hasCompleted() {
return this.array.length === this.index;
};
return StaticArrayIterator;
})();
var ZipBufferIterator = (function (_OuterSubscriber) {
_inherits(ZipBufferIterator, _OuterSubscriber);
function ZipBufferIterator(destination, parent, observable, index) {
_classCallCheck(this, ZipBufferIterator);
_OuterSubscriber.call(this, destination);
this.parent = parent;
this.observable = observable;
this.index = index;
this.stillUnsubscribed = true;
this.buffer = [];
this.isComplete = false;
}
ZipBufferIterator.prototype[_utilSymbol_iterator2['default']] = function () {
return this;
};
// NOTE: there is actually a name collision here with Subscriber.next and Iterator.next
// this is legit because `next()` will never be called by a subscription in this case.
ZipBufferIterator.prototype.next = function next() {
var buffer = this.buffer;
Iif (buffer.length === 0 && this.isComplete) {
return { done: true };
} else {
return { value: buffer.shift(), done: false };
}
};
ZipBufferIterator.prototype.hasValue = function hasValue() {
return this.buffer.length > 0;
};
ZipBufferIterator.prototype.hasCompleted = function hasCompleted() {
return this.buffer.length === 0 && this.isComplete;
};
ZipBufferIterator.prototype.notifyComplete = function notifyComplete() {
if (this.buffer.length > 0) {
this.isComplete = true;
this.parent.notifyInactive();
} else {
this.destination.complete();
}
};
ZipBufferIterator.prototype.notifyNext = function notifyNext(outerValue, innerValue, outerIndex, innerIndex) {
this.buffer.push(innerValue);
this.parent.checkIterators();
};
ZipBufferIterator.prototype.subscribe = function subscribe(value, index) {
this.add(_utilSubscribeToResult2['default'](this, this.observable, this, index));
};
return ZipBufferIterator;
})(_OuterSubscriber3['default']); |