source: trip-planner-front/node_modules/rxjs/_esm5/internal/observable/generate.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.6 KB
RevLine 
[6a3a178]1/** PURE_IMPORTS_START _Observable,_util_identity,_util_isScheduler PURE_IMPORTS_END */
2import { Observable } from '../Observable';
3import { identity } from '../util/identity';
4import { isScheduler } from '../util/isScheduler';
5export function generate(initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler) {
6 var resultSelector;
7 var initialState;
8 if (arguments.length == 1) {
9 var options = initialStateOrOptions;
10 initialState = options.initialState;
11 condition = options.condition;
12 iterate = options.iterate;
13 resultSelector = options.resultSelector || identity;
14 scheduler = options.scheduler;
15 }
16 else if (resultSelectorOrObservable === undefined || isScheduler(resultSelectorOrObservable)) {
17 initialState = initialStateOrOptions;
18 resultSelector = identity;
19 scheduler = resultSelectorOrObservable;
20 }
21 else {
22 initialState = initialStateOrOptions;
23 resultSelector = resultSelectorOrObservable;
24 }
25 return new Observable(function (subscriber) {
26 var state = initialState;
27 if (scheduler) {
28 return scheduler.schedule(dispatch, 0, {
29 subscriber: subscriber,
30 iterate: iterate,
31 condition: condition,
32 resultSelector: resultSelector,
33 state: state
34 });
35 }
36 do {
37 if (condition) {
38 var conditionResult = void 0;
39 try {
40 conditionResult = condition(state);
41 }
42 catch (err) {
43 subscriber.error(err);
44 return undefined;
45 }
46 if (!conditionResult) {
47 subscriber.complete();
48 break;
49 }
50 }
51 var value = void 0;
52 try {
53 value = resultSelector(state);
54 }
55 catch (err) {
56 subscriber.error(err);
57 return undefined;
58 }
59 subscriber.next(value);
60 if (subscriber.closed) {
61 break;
62 }
63 try {
64 state = iterate(state);
65 }
66 catch (err) {
67 subscriber.error(err);
68 return undefined;
69 }
70 } while (true);
71 return undefined;
72 });
73}
74function dispatch(state) {
75 var subscriber = state.subscriber, condition = state.condition;
76 if (subscriber.closed) {
77 return undefined;
78 }
79 if (state.needIterate) {
80 try {
81 state.state = state.iterate(state.state);
82 }
83 catch (err) {
84 subscriber.error(err);
85 return undefined;
86 }
87 }
88 else {
89 state.needIterate = true;
90 }
91 if (condition) {
92 var conditionResult = void 0;
93 try {
94 conditionResult = condition(state.state);
95 }
96 catch (err) {
97 subscriber.error(err);
98 return undefined;
99 }
100 if (!conditionResult) {
101 subscriber.complete();
102 return undefined;
103 }
104 if (subscriber.closed) {
105 return undefined;
106 }
107 }
108 var value;
109 try {
110 value = state.resultSelector(state.state);
111 }
112 catch (err) {
113 subscriber.error(err);
114 return undefined;
115 }
116 if (subscriber.closed) {
117 return undefined;
118 }
119 subscriber.next(value);
120 if (subscriber.closed) {
121 return undefined;
122 }
123 return this.schedule(state);
124}
125//# sourceMappingURL=generate.js.map
Note: See TracBrowser for help on using the repository browser.