[79a0317] | 1 | 'use strict';
|
---|
| 2 | var $ = require('../internals/export');
|
---|
| 3 | var getBuiltIn = require('../internals/get-built-in');
|
---|
| 4 | var call = require('../internals/function-call');
|
---|
| 5 | var anObject = require('../internals/an-object');
|
---|
| 6 | var isConstructor = require('../internals/is-constructor');
|
---|
| 7 | var getIterator = require('../internals/get-iterator');
|
---|
| 8 | var getMethod = require('../internals/get-method');
|
---|
| 9 | var iterate = require('../internals/iterate');
|
---|
| 10 | var wellKnownSymbol = require('../internals/well-known-symbol');
|
---|
| 11 |
|
---|
| 12 | var $$OBSERVABLE = wellKnownSymbol('observable');
|
---|
| 13 |
|
---|
| 14 | // `Observable.from` method
|
---|
| 15 | // https://github.com/tc39/proposal-observable
|
---|
| 16 | $({ target: 'Observable', stat: true, forced: true }, {
|
---|
| 17 | from: function from(x) {
|
---|
| 18 | var C = isConstructor(this) ? this : getBuiltIn('Observable');
|
---|
| 19 | var observableMethod = getMethod(anObject(x), $$OBSERVABLE);
|
---|
| 20 | if (observableMethod) {
|
---|
| 21 | var observable = anObject(call(observableMethod, x));
|
---|
| 22 | return observable.constructor === C ? observable : new C(function (observer) {
|
---|
| 23 | return observable.subscribe(observer);
|
---|
| 24 | });
|
---|
| 25 | }
|
---|
| 26 | var iterator = getIterator(x);
|
---|
| 27 | return new C(function (observer) {
|
---|
| 28 | iterate(iterator, function (it, stop) {
|
---|
| 29 | observer.next(it);
|
---|
| 30 | if (observer.closed) return stop();
|
---|
| 31 | }, { IS_ITERATOR: true, INTERRUPTED: true });
|
---|
| 32 | observer.complete();
|
---|
| 33 | });
|
---|
| 34 | }
|
---|
| 35 | });
|
---|