esnext.observable.of.js 844 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var getBuiltIn = require('../internals/get-built-in');
  4. var isConstructor = require('../internals/is-constructor');
  5. var OBSERVABLE_FORCED = require('../internals/observable-forced');
  6. var Array = getBuiltIn('Array');
  7. // `Observable.of` method
  8. // https://github.com/tc39/proposal-observable
  9. $({ target: 'Observable', stat: true, forced: OBSERVABLE_FORCED }, {
  10. of: function of() {
  11. var C = isConstructor(this) ? this : getBuiltIn('Observable');
  12. var length = arguments.length;
  13. var items = Array(length);
  14. var index = 0;
  15. while (index < length) items[index] = arguments[index++];
  16. return new C(function (observer) {
  17. for (var i = 0; i < length; i++) {
  18. observer.next(items[i]);
  19. if (observer.closed) return;
  20. } observer.complete();
  21. });
  22. }
  23. });