You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
5.4 KiB
1 lines
5.4 KiB
{"ast":null,"code":"import { fromArray } from './fromArray';\nimport { isArray } from '../util/isArray';\nimport { Subscriber } from '../Subscriber';\nimport { iterator as Symbol_iterator } from '../../internal/symbol/iterator';\nimport { SimpleOuterSubscriber, SimpleInnerSubscriber, innerSubscribe } from '../innerSubscribe';\nexport function zip(...observables) {\n const resultSelector = observables[observables.length - 1];\n\n if (typeof resultSelector === 'function') {\n observables.pop();\n }\n\n return fromArray(observables, undefined).lift(new ZipOperator(resultSelector));\n}\nexport class ZipOperator {\n constructor(resultSelector) {\n this.resultSelector = resultSelector;\n }\n\n call(subscriber, source) {\n return source.subscribe(new ZipSubscriber(subscriber, this.resultSelector));\n }\n\n}\nexport class ZipSubscriber extends Subscriber {\n constructor(destination, resultSelector, values = Object.create(null)) {\n super(destination);\n this.resultSelector = resultSelector;\n this.iterators = [];\n this.active = 0;\n this.resultSelector = typeof resultSelector === 'function' ? resultSelector : undefined;\n }\n\n _next(value) {\n const iterators = this.iterators;\n\n if (isArray(value)) {\n iterators.push(new StaticArrayIterator(value));\n } else if (typeof value[Symbol_iterator] === 'function') {\n iterators.push(new StaticIterator(value[Symbol_iterator]()));\n } else {\n iterators.push(new ZipBufferIterator(this.destination, this, value));\n }\n }\n\n _complete() {\n const iterators = this.iterators;\n const len = iterators.length;\n this.unsubscribe();\n\n if (len === 0) {\n this.destination.complete();\n return;\n }\n\n this.active = len;\n\n for (let i = 0; i < len; i++) {\n let iterator = iterators[i];\n\n if (iterator.stillUnsubscribed) {\n const destination = this.destination;\n destination.add(iterator.subscribe());\n } else {\n this.active--;\n }\n }\n }\n\n notifyInactive() {\n this.active--;\n\n if (this.active === 0) {\n this.destination.complete();\n }\n }\n\n checkIterators() {\n const iterators = this.iterators;\n const len = iterators.length;\n const destination = this.destination;\n\n for (let i = 0; i < len; i++) {\n let iterator = iterators[i];\n\n if (typeof iterator.hasValue === 'function' && !iterator.hasValue()) {\n return;\n }\n }\n\n let shouldComplete = false;\n const args = [];\n\n for (let i = 0; i < len; i++) {\n let iterator = iterators[i];\n let result = iterator.next();\n\n if (iterator.hasCompleted()) {\n shouldComplete = true;\n }\n\n if (result.done) {\n destination.complete();\n return;\n }\n\n args.push(result.value);\n }\n\n if (this.resultSelector) {\n this._tryresultSelector(args);\n } else {\n destination.next(args);\n }\n\n if (shouldComplete) {\n destination.complete();\n }\n }\n\n _tryresultSelector(args) {\n let result;\n\n try {\n result = this.resultSelector.apply(this, args);\n } catch (err) {\n this.destination.error(err);\n return;\n }\n\n this.destination.next(result);\n }\n\n}\n\nclass StaticIterator {\n constructor(iterator) {\n this.iterator = iterator;\n this.nextResult = iterator.next();\n }\n\n hasValue() {\n return true;\n }\n\n next() {\n const result = this.nextResult;\n this.nextResult = this.iterator.next();\n return result;\n }\n\n hasCompleted() {\n const nextResult = this.nextResult;\n return Boolean(nextResult && nextResult.done);\n }\n\n}\n\nclass StaticArrayIterator {\n constructor(array) {\n this.array = array;\n this.index = 0;\n this.length = 0;\n this.length = array.length;\n }\n\n [Symbol_iterator]() {\n return this;\n }\n\n next(value) {\n const i = this.index++;\n const array = this.array;\n return i < this.length ? {\n value: array[i],\n done: false\n } : {\n value: null,\n done: true\n };\n }\n\n hasValue() {\n return this.array.length > this.index;\n }\n\n hasCompleted() {\n return this.array.length === this.index;\n }\n\n}\n\nclass ZipBufferIterator extends SimpleOuterSubscriber {\n constructor(destination, parent, observable) {\n super(destination);\n this.parent = parent;\n this.observable = observable;\n this.stillUnsubscribed = true;\n this.buffer = [];\n this.isComplete = false;\n }\n\n [Symbol_iterator]() {\n return this;\n }\n\n next() {\n const buffer = this.buffer;\n\n if (buffer.length === 0 && this.isComplete) {\n return {\n value: null,\n done: true\n };\n } else {\n return {\n value: buffer.shift(),\n done: false\n };\n }\n }\n\n hasValue() {\n return this.buffer.length > 0;\n }\n\n hasCompleted() {\n return this.buffer.length === 0 && this.isComplete;\n }\n\n notifyComplete() {\n if (this.buffer.length > 0) {\n this.isComplete = true;\n this.parent.notifyInactive();\n } else {\n this.destination.complete();\n }\n }\n\n notifyNext(innerValue) {\n this.buffer.push(innerValue);\n this.parent.checkIterators();\n }\n\n subscribe() {\n return innerSubscribe(this.observable, new SimpleInnerSubscriber(this));\n }\n\n} //# sourceMappingURL=zip.js.map","map":null,"metadata":{},"sourceType":"module"}
|