Node-Red configuration
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.

esnext.observable.from.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435
  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. var $$OBSERVABLE = wellKnownSymbol('observable');
  12. // `Observable.from` method
  13. // https://github.com/tc39/proposal-observable
  14. $({ target: 'Observable', stat: true, forced: true }, {
  15. from: function from(x) {
  16. var C = isConstructor(this) ? this : getBuiltIn('Observable');
  17. var observableMethod = getMethod(anObject(x), $$OBSERVABLE);
  18. if (observableMethod) {
  19. var observable = anObject(call(observableMethod, x));
  20. return observable.constructor === C ? observable : new C(function (observer) {
  21. return observable.subscribe(observer);
  22. });
  23. }
  24. var iterator = getIterator(x);
  25. return new C(function (observer) {
  26. iterate(iterator, function (it, stop) {
  27. observer.next(it);
  28. if (observer.closed) return stop();
  29. }, { IS_ITERATOR: true, INTERRUPTED: true });
  30. observer.complete();
  31. });
  32. }
  33. });