"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var fetcherUtils_1 = require("./fetcherUtils");
var AbstractObservable = (function () {
function AbstractObservable() {
var _this = this;
this.onNext = function (data) {
_this.subscribers.forEach(function (subscriber) { return setTimeout(function () { return subscriber.next(data); }, 0); });
};
this.onError = function (error) {
_this.subscribers.forEach(function (subscriber) { return subscriber.error ? setTimeout(function () { return subscriber.error(error); }, 0) : null; });
_this.terminate();
};
this.onComplete = function () {
_this.subscribers.forEach(function (subscriber) { return subscriber.complete ? setTimeout(subscriber.complete, 0) : null; });
_this.terminate();
};
this.terminate = function () {
_this.subscribers = [];
_this.terminated = true;
};
this.subscribers = [];
this.onNext = this.onNext.bind(this);
this.onError = this.onError.bind(this);
this.onComplete = this.onComplete.bind(this);
this.terminated = false;
}
AbstractObservable.prototype.subscribe = function (nextOrSubscriber, error, complete) {
var subscriber = fetcherUtils_1.toSubscriber(nextOrSubscriber, error, complete);
if (this.terminated) {
Eif (subscriber.complete) {
subscriber.complete();
}
return {
get closed() { return true; },
unsubscribe: function () { return void 0; },
};
}
this.subscribers.push(subscriber);
if (this.subscribers.length === 1) {
this.start();
}
return (function (subscribers) {
var stopped = false;
return {
get closed() {
return stopped;
},
unsubscribe: function () {
subscribers.splice(subscribers.indexOf(subscriber), 1);
stopped = true;
},
};
})(this.subscribers);
};
return AbstractObservable;
}());
exports.default = AbstractObservable;
//# sourceMappingURL=abstractObservable.js.map |