1 /** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_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 './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;
11 this._subscribe = subscribe;
14 Observable.prototype.lift = function (operator) {
15 var observable = new Observable();
16 observable.source = this;
17 observable.operator = operator;
20 Observable.prototype.subscribe = function (observerOrNext, error, complete) {
21 var operator = this.operator;
22 var sink = toSubscriber(observerOrNext, error, complete);
24 sink.add(operator.call(sink, this.source));
27 sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
28 this._subscribe(sink) :
29 this._trySubscribe(sink));
31 if (config.useDeprecatedSynchronousErrorHandling) {
32 if (sink.syncErrorThrowable) {
33 sink.syncErrorThrowable = false;
34 if (sink.syncErrorThrown) {
35 throw sink.syncErrorValue;
41 Observable.prototype._trySubscribe = function (sink) {
43 return this._subscribe(sink);
46 if (config.useDeprecatedSynchronousErrorHandling) {
47 sink.syncErrorThrown = true;
48 sink.syncErrorValue = err;
50 if (canReportError(sink)) {
58 Observable.prototype.forEach = function (next, promiseCtor) {
60 promiseCtor = getPromiseCtor(promiseCtor);
61 return new promiseCtor(function (resolve, reject) {
63 subscription = _this.subscribe(function (value) {
70 subscription.unsubscribe();
76 Observable.prototype._subscribe = function (subscriber) {
77 var source = this.source;
78 return source && source.subscribe(subscriber);
80 Observable.prototype[Symbol_observable] = function () {
83 Observable.prototype.pipe = function () {
85 for (var _i = 0; _i < arguments.length; _i++) {
86 operations[_i] = arguments[_i];
88 if (operations.length === 0) {
91 return pipeFromArray(operations)(this);
93 Observable.prototype.toPromise = function (promiseCtor) {
95 promiseCtor = getPromiseCtor(promiseCtor);
96 return new promiseCtor(function (resolve, reject) {
98 _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
101 Observable.create = function (subscribe) {
102 return new Observable(subscribe);
106 export { Observable };
107 function getPromiseCtor(promiseCtor) {
109 promiseCtor = config.Promise || Promise;
112 throw new Error('no Promise impl found');
116 //# sourceMappingURL=Observable.js.map