generate.js
3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Observable_1 = require("../Observable");
var identity_1 = require("../util/identity");
var isScheduler_1 = require("../util/isScheduler");
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_1.identity;
scheduler = options.scheduler;
}
else if (resultSelectorOrObservable === undefined || isScheduler_1.isScheduler(resultSelectorOrObservable)) {
initialState = initialStateOrOptions;
resultSelector = identity_1.identity;
scheduler = resultSelectorOrObservable;
}
else {
initialState = initialStateOrOptions;
resultSelector = resultSelectorOrObservable;
}
return new Observable_1.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;
});
}
exports.generate = generate;
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