1 /** PURE_IMPORTS_START tslib,_fromArray,_util_isArray,_Subscriber,_OuterSubscriber,_util_subscribeToResult,_.._internal_symbol_iterator 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 { OuterSubscriber } from '../OuterSubscriber';
7 import { subscribeToResult } from '../util/subscribeToResult';
8 import { iterator as Symbol_iterator } from '../../internal/symbol/iterator';
9 export function zip() {
11 for (var _i = 0; _i < arguments.length; _i++) {
12 observables[_i] = arguments[_i];
14 var resultSelector = observables[observables.length - 1];
15 if (typeof resultSelector === 'function') {
18 return fromArray(observables, undefined).lift(new ZipOperator(resultSelector));
20 var ZipOperator = /*@__PURE__*/ (function () {
21 function ZipOperator(resultSelector) {
22 this.resultSelector = resultSelector;
24 ZipOperator.prototype.call = function (subscriber, source) {
25 return source.subscribe(new ZipSubscriber(subscriber, this.resultSelector));
29 export { ZipOperator };
30 var ZipSubscriber = /*@__PURE__*/ (function (_super) {
31 tslib_1.__extends(ZipSubscriber, _super);
32 function ZipSubscriber(destination, resultSelector, values) {
33 if (values === void 0) {
34 values = Object.create(null);
36 var _this = _super.call(this, destination) || this;
39 _this.resultSelector = (typeof resultSelector === 'function') ? resultSelector : null;
40 _this.values = values;
43 ZipSubscriber.prototype._next = function (value) {
44 var iterators = this.iterators;
46 iterators.push(new StaticArrayIterator(value));
48 else if (typeof value[Symbol_iterator] === 'function') {
49 iterators.push(new StaticIterator(value[Symbol_iterator]()));
52 iterators.push(new ZipBufferIterator(this.destination, this, value));
55 ZipSubscriber.prototype._complete = function () {
56 var iterators = this.iterators;
57 var len = iterators.length;
60 this.destination.complete();
64 for (var i = 0; i < len; i++) {
65 var iterator = iterators[i];
66 if (iterator.stillUnsubscribed) {
67 var destination = this.destination;
68 destination.add(iterator.subscribe(iterator, i));
75 ZipSubscriber.prototype.notifyInactive = function () {
77 if (this.active === 0) {
78 this.destination.complete();
81 ZipSubscriber.prototype.checkIterators = function () {
82 var iterators = this.iterators;
83 var len = iterators.length;
84 var destination = this.destination;
85 for (var i = 0; i < len; i++) {
86 var iterator = iterators[i];
87 if (typeof iterator.hasValue === 'function' && !iterator.hasValue()) {
91 var shouldComplete = false;
93 for (var i = 0; i < len; i++) {
94 var iterator = iterators[i];
95 var result = iterator.next();
96 if (iterator.hasCompleted()) {
97 shouldComplete = true;
100 destination.complete();
103 args.push(result.value);
105 if (this.resultSelector) {
106 this._tryresultSelector(args);
109 destination.next(args);
111 if (shouldComplete) {
112 destination.complete();
115 ZipSubscriber.prototype._tryresultSelector = function (args) {
118 result = this.resultSelector.apply(this, args);
121 this.destination.error(err);
124 this.destination.next(result);
126 return ZipSubscriber;
128 export { ZipSubscriber };
129 var StaticIterator = /*@__PURE__*/ (function () {
130 function StaticIterator(iterator) {
131 this.iterator = iterator;
132 this.nextResult = iterator.next();
134 StaticIterator.prototype.hasValue = function () {
137 StaticIterator.prototype.next = function () {
138 var result = this.nextResult;
139 this.nextResult = this.iterator.next();
142 StaticIterator.prototype.hasCompleted = function () {
143 var nextResult = this.nextResult;
144 return nextResult && nextResult.done;
146 return StaticIterator;
148 var StaticArrayIterator = /*@__PURE__*/ (function () {
149 function StaticArrayIterator(array) {
153 this.length = array.length;
155 StaticArrayIterator.prototype[Symbol_iterator] = function () {
158 StaticArrayIterator.prototype.next = function (value) {
159 var i = this.index++;
160 var array = this.array;
161 return i < this.length ? { value: array[i], done: false } : { value: null, done: true };
163 StaticArrayIterator.prototype.hasValue = function () {
164 return this.array.length > this.index;
166 StaticArrayIterator.prototype.hasCompleted = function () {
167 return this.array.length === this.index;
169 return StaticArrayIterator;
171 var ZipBufferIterator = /*@__PURE__*/ (function (_super) {
172 tslib_1.__extends(ZipBufferIterator, _super);
173 function ZipBufferIterator(destination, parent, observable) {
174 var _this = _super.call(this, destination) || this;
175 _this.parent = parent;
176 _this.observable = observable;
177 _this.stillUnsubscribed = true;
179 _this.isComplete = false;
182 ZipBufferIterator.prototype[Symbol_iterator] = function () {
185 ZipBufferIterator.prototype.next = function () {
186 var buffer = this.buffer;
187 if (buffer.length === 0 && this.isComplete) {
188 return { value: null, done: true };
191 return { value: buffer.shift(), done: false };
194 ZipBufferIterator.prototype.hasValue = function () {
195 return this.buffer.length > 0;
197 ZipBufferIterator.prototype.hasCompleted = function () {
198 return this.buffer.length === 0 && this.isComplete;
200 ZipBufferIterator.prototype.notifyComplete = function () {
201 if (this.buffer.length > 0) {
202 this.isComplete = true;
203 this.parent.notifyInactive();
206 this.destination.complete();
209 ZipBufferIterator.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
210 this.buffer.push(innerValue);
211 this.parent.checkIterators();
213 ZipBufferIterator.prototype.subscribe = function (value, index) {
214 return subscribeToResult(this, this.observable, this, index);
216 return ZipBufferIterator;
218 //# sourceMappingURL=zip.js.map