GenerateObservable.js
4.6 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
128
129
130
131
132
133
134
135
"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);
};
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