1 /** PURE_IMPORTS_START tslib,_fromArray,_util_isArray,_Subscriber,_.._internal_symbol_iterator,_innerSubscribe PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { fromArray } from './fromArray';
4 import { isArray } from '../util/isArray';
5 import { Subscriber } from '../Subscriber';
6 import { iterator as Symbol_iterator } from '../../internal/symbol/iterator';
7 import { SimpleOuterSubscriber, SimpleInnerSubscriber, innerSubscribe } from '../innerSubscribe';
8 export function zip() {
10 for (var _i = 0; _i < arguments.length; _i++) {
11 observables[_i] = arguments[_i];
13 var resultSelector = observables[observables.length - 1];
14 if (typeof resultSelector === 'function') {
17 return fromArray(observables, undefined).lift(new ZipOperator(resultSelector));
19 var ZipOperator = /*@__PURE__*/ (function () {
20 function ZipOperator(resultSelector) {
21 this.resultSelector = resultSelector;
23 ZipOperator.prototype.call = function (subscriber, source) {
24 return source.subscribe(new ZipSubscriber(subscriber, this.resultSelector));
28 export { ZipOperator };
29 var ZipSubscriber = /*@__PURE__*/ (function (_super) {
30 tslib_1.__extends(ZipSubscriber, _super);
31 function ZipSubscriber(destination, resultSelector, values) {
32 if (values === void 0) {
33 values = Object.create(null);
35 var _this = _super.call(this, destination) || this;
36 _this.resultSelector = resultSelector;
39 _this.resultSelector = (typeof resultSelector === 'function') ? resultSelector : undefined;
42 ZipSubscriber.prototype._next = function (value) {
43 var iterators = this.iterators;
45 iterators.push(new StaticArrayIterator(value));
47 else if (typeof value[Symbol_iterator] === 'function') {
48 iterators.push(new StaticIterator(value[Symbol_iterator]()));
51 iterators.push(new ZipBufferIterator(this.destination, this, value));
54 ZipSubscriber.prototype._complete = function () {
55 var iterators = this.iterators;
56 var len = iterators.length;
59 this.destination.complete();
63 for (var i = 0; i < len; i++) {
64 var iterator = iterators[i];
65 if (iterator.stillUnsubscribed) {
66 var destination = this.destination;
67 destination.add(iterator.subscribe());
74 ZipSubscriber.prototype.notifyInactive = function () {
76 if (this.active === 0) {
77 this.destination.complete();
80 ZipSubscriber.prototype.checkIterators = function () {
81 var iterators = this.iterators;
82 var len = iterators.length;
83 var destination = this.destination;
84 for (var i = 0; i < len; i++) {
85 var iterator = iterators[i];
86 if (typeof iterator.hasValue === 'function' && !iterator.hasValue()) {
90 var shouldComplete = false;
92 for (var i = 0; i < len; i++) {
93 var iterator = iterators[i];
94 var result = iterator.next();
95 if (iterator.hasCompleted()) {
96 shouldComplete = true;
99 destination.complete();
102 args.push(result.value);
104 if (this.resultSelector) {
105 this._tryresultSelector(args);
108 destination.next(args);
110 if (shouldComplete) {
111 destination.complete();
114 ZipSubscriber.prototype._tryresultSelector = function (args) {
117 result = this.resultSelector.apply(this, args);
120 this.destination.error(err);
123 this.destination.next(result);
125 return ZipSubscriber;
127 export { ZipSubscriber };
128 var StaticIterator = /*@__PURE__*/ (function () {
129 function StaticIterator(iterator) {
130 this.iterator = iterator;
131 this.nextResult = iterator.next();
133 StaticIterator.prototype.hasValue = function () {
136 StaticIterator.prototype.next = function () {
137 var result = this.nextResult;
138 this.nextResult = this.iterator.next();
141 StaticIterator.prototype.hasCompleted = function () {
142 var nextResult = this.nextResult;
143 return Boolean(nextResult && nextResult.done);
145 return StaticIterator;
147 var StaticArrayIterator = /*@__PURE__*/ (function () {
148 function StaticArrayIterator(array) {
152 this.length = array.length;
154 StaticArrayIterator.prototype[Symbol_iterator] = function () {
157 StaticArrayIterator.prototype.next = function (value) {
158 var i = this.index++;
159 var array = this.array;
160 return i < this.length ? { value: array[i], done: false } : { value: null, done: true };
162 StaticArrayIterator.prototype.hasValue = function () {
163 return this.array.length > this.index;
165 StaticArrayIterator.prototype.hasCompleted = function () {
166 return this.array.length === this.index;
168 return StaticArrayIterator;
170 var ZipBufferIterator = /*@__PURE__*/ (function (_super) {
171 tslib_1.__extends(ZipBufferIterator, _super);
172 function ZipBufferIterator(destination, parent, observable) {
173 var _this = _super.call(this, destination) || this;
174 _this.parent = parent;
175 _this.observable = observable;
176 _this.stillUnsubscribed = true;
178 _this.isComplete = false;
181 ZipBufferIterator.prototype[Symbol_iterator] = function () {
184 ZipBufferIterator.prototype.next = function () {
185 var buffer = this.buffer;
186 if (buffer.length === 0 && this.isComplete) {
187 return { value: null, done: true };
190 return { value: buffer.shift(), done: false };
193 ZipBufferIterator.prototype.hasValue = function () {
194 return this.buffer.length > 0;
196 ZipBufferIterator.prototype.hasCompleted = function () {
197 return this.buffer.length === 0 && this.isComplete;
199 ZipBufferIterator.prototype.notifyComplete = function () {
200 if (this.buffer.length > 0) {
201 this.isComplete = true;
202 this.parent.notifyInactive();
205 this.destination.complete();
208 ZipBufferIterator.prototype.notifyNext = function (innerValue) {
209 this.buffer.push(innerValue);
210 this.parent.checkIterators();
212 ZipBufferIterator.prototype.subscribe = function () {
213 return innerSubscribe(this.observable, new SimpleInnerSubscriber(this));
215 return ZipBufferIterator;
216 }(SimpleOuterSubscriber));
217 //# sourceMappingURL=zip.js.map