71 lines
3.1 KiB
JavaScript
71 lines
3.1 KiB
JavaScript
"use strict";
|
|
var __extends = (this && this.__extends) || function (d, b) {
|
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
var isArray_1 = require('../util/isArray');
|
|
var isFunction_1 = require('../util/isFunction');
|
|
var isPromise_1 = require('../util/isPromise');
|
|
var isScheduler_1 = require('../util/isScheduler');
|
|
var PromiseObservable_1 = require('./PromiseObservable');
|
|
var IteratorObservable_1 = require('./IteratorObservable');
|
|
var ArrayObservable_1 = require('./ArrayObservable');
|
|
var ArrayLikeObservable_1 = require('./ArrayLikeObservable');
|
|
var SymbolShim_1 = require('../util/SymbolShim');
|
|
var Observable_1 = require('../Observable');
|
|
var observeOn_1 = require('../operator/observeOn');
|
|
var isArrayLike = (function (x) { return x && typeof x.length === 'number'; });
|
|
var FromObservable = (function (_super) {
|
|
__extends(FromObservable, _super);
|
|
function FromObservable(ish, scheduler) {
|
|
_super.call(this, null);
|
|
this.ish = ish;
|
|
this.scheduler = scheduler;
|
|
}
|
|
FromObservable.create = function (ish, mapFnOrScheduler, thisArg, lastScheduler) {
|
|
var scheduler = null;
|
|
var mapFn = null;
|
|
if (isFunction_1.isFunction(mapFnOrScheduler)) {
|
|
scheduler = lastScheduler || null;
|
|
mapFn = mapFnOrScheduler;
|
|
}
|
|
else if (isScheduler_1.isScheduler(scheduler)) {
|
|
scheduler = mapFnOrScheduler;
|
|
}
|
|
if (ish != null) {
|
|
if (typeof ish[SymbolShim_1.SymbolShim.observable] === 'function') {
|
|
if (ish instanceof Observable_1.Observable && !scheduler) {
|
|
return ish;
|
|
}
|
|
return new FromObservable(ish, scheduler);
|
|
}
|
|
else if (isArray_1.isArray(ish)) {
|
|
return new ArrayObservable_1.ArrayObservable(ish, scheduler);
|
|
}
|
|
else if (isPromise_1.isPromise(ish)) {
|
|
return new PromiseObservable_1.PromiseObservable(ish, scheduler);
|
|
}
|
|
else if (typeof ish[SymbolShim_1.SymbolShim.iterator] === 'function' || typeof ish === 'string') {
|
|
return new IteratorObservable_1.IteratorObservable(ish, null, null, scheduler);
|
|
}
|
|
else if (isArrayLike(ish)) {
|
|
return new ArrayLikeObservable_1.ArrayLikeObservable(ish, mapFn, thisArg, scheduler);
|
|
}
|
|
}
|
|
throw new TypeError((ish !== null && typeof ish || ish) + ' is not observable');
|
|
};
|
|
FromObservable.prototype._subscribe = function (subscriber) {
|
|
var ish = this.ish;
|
|
var scheduler = this.scheduler;
|
|
if (scheduler == null) {
|
|
return ish[SymbolShim_1.SymbolShim.observable]().subscribe(subscriber);
|
|
}
|
|
else {
|
|
return ish[SymbolShim_1.SymbolShim.observable]().subscribe(new observeOn_1.ObserveOnSubscriber(subscriber, scheduler, 0));
|
|
}
|
|
};
|
|
return FromObservable;
|
|
}(Observable_1.Observable));
|
|
exports.FromObservable = FromObservable;
|
|
//# sourceMappingURL=FromObservable.js.map
|