123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- import { Observable } from '../Observable';
- import { isScheduler } from '../util/isScheduler';
- const selfSelector = (value) => value;
- /**
- * We need this JSDoc comment for affecting ESDoc.
- * @extends {Ignored}
- * @hide true
- */
- export class GenerateObservable extends Observable {
- constructor(initialState, condition, iterate, resultSelector, scheduler) {
- super();
- this.initialState = initialState;
- this.condition = condition;
- this.iterate = iterate;
- this.resultSelector = resultSelector;
- this.scheduler = scheduler;
- }
- static create(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(resultSelectorOrObservable)) {
- return new GenerateObservable(initialStateOrOptions, condition, iterate, selfSelector, resultSelectorOrObservable);
- }
- return new GenerateObservable(initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler);
- }
- /** @deprecated internal use only */ _subscribe(subscriber) {
- let state = this.initialState;
- if (this.scheduler) {
- return this.scheduler.schedule(GenerateObservable.dispatch, 0, {
- subscriber,
- iterate: this.iterate,
- condition: this.condition,
- resultSelector: this.resultSelector,
- state });
- }
- const { condition, resultSelector, iterate } = this;
- do {
- if (condition) {
- let conditionResult;
- try {
- conditionResult = condition(state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- if (!conditionResult) {
- subscriber.complete();
- break;
- }
- }
- let value;
- 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);
- }
- static dispatch(state) {
- const { subscriber, condition } = state;
- 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) {
- let conditionResult;
- try {
- conditionResult = condition(state.state);
- }
- catch (err) {
- subscriber.error(err);
- return;
- }
- if (!conditionResult) {
- subscriber.complete();
- return;
- }
- if (subscriber.closed) {
- return;
- }
- }
- let 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);
- }
- }
- //# sourceMappingURL=GenerateObservable.js.map
|