2 Object.defineProperty(exports, "__esModule", { value: true });
3 var canReportError_1 = require("./util/canReportError");
4 var toSubscriber_1 = require("./util/toSubscriber");
5 var observable_1 = require("./symbol/observable");
6 var pipe_1 = require("./util/pipe");
7 var config_1 = require("./config");
8 var Observable = (function () {
9 function Observable(subscribe) {
10 this._isScalar = false;
12 this._subscribe = subscribe;
15 Observable.prototype.lift = function (operator) {
16 var observable = new Observable();
17 observable.source = this;
18 observable.operator = operator;
21 Observable.prototype.subscribe = function (observerOrNext, error, complete) {
22 var operator = this.operator;
23 var sink = toSubscriber_1.toSubscriber(observerOrNext, error, complete);
25 sink.add(operator.call(sink, this.source));
28 sink.add(this.source || (config_1.config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
29 this._subscribe(sink) :
30 this._trySubscribe(sink));
32 if (config_1.config.useDeprecatedSynchronousErrorHandling) {
33 if (sink.syncErrorThrowable) {
34 sink.syncErrorThrowable = false;
35 if (sink.syncErrorThrown) {
36 throw sink.syncErrorValue;
42 Observable.prototype._trySubscribe = function (sink) {
44 return this._subscribe(sink);
47 if (config_1.config.useDeprecatedSynchronousErrorHandling) {
48 sink.syncErrorThrown = true;
49 sink.syncErrorValue = err;
51 if (canReportError_1.canReportError(sink)) {
59 Observable.prototype.forEach = function (next, promiseCtor) {
61 promiseCtor = getPromiseCtor(promiseCtor);
62 return new promiseCtor(function (resolve, reject) {
64 subscription = _this.subscribe(function (value) {
71 subscription.unsubscribe();
77 Observable.prototype._subscribe = function (subscriber) {
78 var source = this.source;
79 return source && source.subscribe(subscriber);
81 Observable.prototype[observable_1.observable] = function () {
84 Observable.prototype.pipe = function () {
86 for (var _i = 0; _i < arguments.length; _i++) {
87 operations[_i] = arguments[_i];
89 if (operations.length === 0) {
92 return pipe_1.pipeFromArray(operations)(this);
94 Observable.prototype.toPromise = function (promiseCtor) {
96 promiseCtor = getPromiseCtor(promiseCtor);
97 return new promiseCtor(function (resolve, reject) {
99 _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
102 Observable.create = function (subscribe) {
103 return new Observable(subscribe);
107 exports.Observable = Observable;
108 function getPromiseCtor(promiseCtor) {
110 promiseCtor = config_1.config.Promise || Promise;
113 throw new Error('no Promise impl found');
117 //# sourceMappingURL=Observable.js.map