123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- "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 Observable_1 = require('../Observable');
- var isScheduler_1 = require('../util/isScheduler');
- var selfSelector = function (value) { return value; };
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- var GenerateObservable = (function (_super) {
- __extends(GenerateObservable, _super);
- function GenerateObservable(initialState, condition, iterate, resultSelector, scheduler) {
- _super.call(this);
- this.initialState = initialState;
- this.condition = condition;
- this.iterate = iterate;
- this.resultSelector = resultSelector;
- this.scheduler = scheduler;
- }
- GenerateObservable.create = function (initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler) {
- if (arguments.length == 1) {
- return new GenerateObservable(initialStateOrOptions.initialState, initialStateOrOptions.condition, initialStateOrOptions.iterate, initialStateOrOptions.resultSelector || selfSelector, initialStateOrOptions.scheduler);
- }
- if (resultSelectorOrObservable === undefined || isScheduler_1.isScheduler(resultSelectorOrObservable)) {
- return new GenerateObservable(initialStateOrOptions, condition, iterate, selfSelector, resultSelectorOrObservable);
- }
- return new GenerateObservable(initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler);
- };
- /** @deprecated internal use only */ GenerateObservable.prototype._subscribe = function (subscriber) {
- var state = this.initialState;
- if (this.scheduler) {
- return this.scheduler.schedule(GenerateObservable.dispatch, 0, {
- subscriber: subscriber,
- iterate: this.iterate,
- condition: this.condition,
- resultSelector: this.resultSelector,
- state: state });
- }
- var _a = this, condition = _a.condition, resultSelector = _a.resultSelector, iterate = _a.iterate;
- do {
- if (condition) {
- var conditionResult = void 0;
- try {
- conditionResult = condition(state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- if (!conditionResult) {
- subscriber.complete();
- break;
- }
- }
- var value = void 0;
- try {
- value = resultSelector(state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- subscriber.next(value);
- if (subscriber.closed) {
- break;
- }
- try {
- state = iterate(state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- } while (true);
- };
- GenerateObservable.dispatch = function (state) {
- var subscriber = state.subscriber, condition = state.condition;
- if (subscriber.closed) {
- return;
- }
- if (state.needIterate) {
- try {
- state.state = state.iterate(state.state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- }
- else {
- state.needIterate = true;
- }
- if (condition) {
- var conditionResult = void 0;
- try {
- conditionResult = condition(state.state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- if (!conditionResult) {
- subscriber.complete();
- return;
- }
- if (subscriber.closed) {
- return;
- }
- }
- var value;
- try {
- value = state.resultSelector(state.state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- if (subscriber.closed) {
- return;
- }
- subscriber.next(value);
- if (subscriber.closed) {
- return;
- }
- return this.schedule(state);
- };
- return GenerateObservable;
- }(Observable_1.Observable));
- exports.GenerateObservable = GenerateObservable;
- //# sourceMappingURL=GenerateObservable.js.map
|