123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- /** PURE_IMPORTS_START _Observable,_util_identity,_util_isScheduler PURE_IMPORTS_END */
- import { Observable } from '../Observable';
- import { identity } from '../util/identity';
- import { isScheduler } from '../util/isScheduler';
- export function generate(initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler) {
- var resultSelector;
- var initialState;
- if (arguments.length == 1) {
- var options = initialStateOrOptions;
- initialState = options.initialState;
- condition = options.condition;
- iterate = options.iterate;
- resultSelector = options.resultSelector || identity;
- scheduler = options.scheduler;
- }
- else if (resultSelectorOrObservable === undefined || isScheduler(resultSelectorOrObservable)) {
- initialState = initialStateOrOptions;
- resultSelector = identity;
- scheduler = resultSelectorOrObservable;
- }
- else {
- initialState = initialStateOrOptions;
- resultSelector = resultSelectorOrObservable;
- }
- return new Observable(function (subscriber) {
- var state = initialState;
- if (scheduler) {
- return scheduler.schedule(dispatch, 0, {
- subscriber: subscriber,
- iterate: iterate,
- condition: condition,
- resultSelector: resultSelector,
- state: state
- });
- }
- do {
- if (condition) {
- var conditionResult = void 0;
- try {
- conditionResult = condition(state);
- }
- catch (err) {
- subscriber.error(err);
- return undefined;
- }
- if (!conditionResult) {
- subscriber.complete();
- break;
- }
- }
- var value = void 0;
- try {
- value = resultSelector(state);
- }
- catch (err) {
- subscriber.error(err);
- return undefined;
- }
- subscriber.next(value);
- if (subscriber.closed) {
- break;
- }
- try {
- state = iterate(state);
- }
- catch (err) {
- subscriber.error(err);
- return undefined;
- }
- } while (true);
- return undefined;
- });
- }
- function dispatch(state) {
- var subscriber = state.subscriber, condition = state.condition;
- if (subscriber.closed) {
- return undefined;
- }
- if (state.needIterate) {
- try {
- state.state = state.iterate(state.state);
- }
- catch (err) {
- subscriber.error(err);
- return undefined;
- }
- }
- else {
- state.needIterate = true;
- }
- if (condition) {
- var conditionResult = void 0;
- try {
- conditionResult = condition(state.state);
- }
- catch (err) {
- subscriber.error(err);
- return undefined;
- }
- if (!conditionResult) {
- subscriber.complete();
- return undefined;
- }
- if (subscriber.closed) {
- return undefined;
- }
- }
- var value;
- try {
- value = state.resultSelector(state.state);
- }
- catch (err) {
- subscriber.error(err);
- return undefined;
- }
- if (subscriber.closed) {
- return undefined;
- }
- subscriber.next(value);
- if (subscriber.closed) {
- return undefined;
- }
- return this.schedule(state);
- }
- //# sourceMappingURL=generate.js.map
|