Ohm-Management - Projektarbeit B-ME
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.

Observable.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_internal_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */
  2. import { canReportError } from './util/canReportError';
  3. import { toSubscriber } from './util/toSubscriber';
  4. import { observable as Symbol_observable } from '../internal/symbol/observable';
  5. import { pipeFromArray } from './util/pipe';
  6. import { config } from './config';
  7. var Observable = /*@__PURE__*/ (function () {
  8. function Observable(subscribe) {
  9. this._isScalar = false;
  10. if (subscribe) {
  11. this._subscribe = subscribe;
  12. }
  13. }
  14. Observable.prototype.lift = function (operator) {
  15. var observable = new Observable();
  16. observable.source = this;
  17. observable.operator = operator;
  18. return observable;
  19. };
  20. Observable.prototype.subscribe = function (observerOrNext, error, complete) {
  21. var operator = this.operator;
  22. var sink = toSubscriber(observerOrNext, error, complete);
  23. if (operator) {
  24. operator.call(sink, this.source);
  25. }
  26. else {
  27. sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
  28. this._subscribe(sink) :
  29. this._trySubscribe(sink));
  30. }
  31. if (config.useDeprecatedSynchronousErrorHandling) {
  32. if (sink.syncErrorThrowable) {
  33. sink.syncErrorThrowable = false;
  34. if (sink.syncErrorThrown) {
  35. throw sink.syncErrorValue;
  36. }
  37. }
  38. }
  39. return sink;
  40. };
  41. Observable.prototype._trySubscribe = function (sink) {
  42. try {
  43. return this._subscribe(sink);
  44. }
  45. catch (err) {
  46. if (config.useDeprecatedSynchronousErrorHandling) {
  47. sink.syncErrorThrown = true;
  48. sink.syncErrorValue = err;
  49. }
  50. if (canReportError(sink)) {
  51. sink.error(err);
  52. }
  53. else {
  54. console.warn(err);
  55. }
  56. }
  57. };
  58. Observable.prototype.forEach = function (next, promiseCtor) {
  59. var _this = this;
  60. promiseCtor = getPromiseCtor(promiseCtor);
  61. return new promiseCtor(function (resolve, reject) {
  62. var subscription;
  63. subscription = _this.subscribe(function (value) {
  64. try {
  65. next(value);
  66. }
  67. catch (err) {
  68. reject(err);
  69. if (subscription) {
  70. subscription.unsubscribe();
  71. }
  72. }
  73. }, reject, resolve);
  74. });
  75. };
  76. Observable.prototype._subscribe = function (subscriber) {
  77. var source = this.source;
  78. return source && source.subscribe(subscriber);
  79. };
  80. Observable.prototype[Symbol_observable] = function () {
  81. return this;
  82. };
  83. Observable.prototype.pipe = function () {
  84. var operations = [];
  85. for (var _i = 0; _i < arguments.length; _i++) {
  86. operations[_i] = arguments[_i];
  87. }
  88. if (operations.length === 0) {
  89. return this;
  90. }
  91. return pipeFromArray(operations)(this);
  92. };
  93. Observable.prototype.toPromise = function (promiseCtor) {
  94. var _this = this;
  95. promiseCtor = getPromiseCtor(promiseCtor);
  96. return new promiseCtor(function (resolve, reject) {
  97. var value;
  98. _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
  99. });
  100. };
  101. Observable.create = function (subscribe) {
  102. return new Observable(subscribe);
  103. };
  104. return Observable;
  105. }());
  106. export { Observable };
  107. function getPromiseCtor(promiseCtor) {
  108. if (!promiseCtor) {
  109. promiseCtor = config.Promise || Promise;
  110. }
  111. if (!promiseCtor) {
  112. throw new Error('no Promise impl found');
  113. }
  114. return promiseCtor;
  115. }
  116. //# sourceMappingURL=Observable.js.map