49 lines
No EOL
1.8 KiB
JavaScript
49 lines
No EOL
1.8 KiB
JavaScript
import { __generator } from "tslib";
|
|
import { identity } from '../util/identity';
|
|
import { isScheduler } from '../util/isScheduler';
|
|
import { defer } from './defer';
|
|
import { scheduleIterable } from '../scheduled/scheduleIterable';
|
|
export function generate(initialStateOrOptions, condition, iterate, resultSelectorOrScheduler, scheduler) {
|
|
var _a, _b;
|
|
var resultSelector;
|
|
var initialState;
|
|
if (arguments.length === 1) {
|
|
(_a = initialStateOrOptions, initialState = _a.initialState, condition = _a.condition, iterate = _a.iterate, _b = _a.resultSelector, resultSelector = _b === void 0 ? identity : _b, scheduler = _a.scheduler);
|
|
}
|
|
else {
|
|
initialState = initialStateOrOptions;
|
|
if (!resultSelectorOrScheduler || isScheduler(resultSelectorOrScheduler)) {
|
|
resultSelector = identity;
|
|
scheduler = resultSelectorOrScheduler;
|
|
}
|
|
else {
|
|
resultSelector = resultSelectorOrScheduler;
|
|
}
|
|
}
|
|
function gen() {
|
|
var state;
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
state = initialState;
|
|
_a.label = 1;
|
|
case 1:
|
|
if (!(!condition || condition(state))) return [3, 4];
|
|
return [4, resultSelector(state)];
|
|
case 2:
|
|
_a.sent();
|
|
_a.label = 3;
|
|
case 3:
|
|
state = iterate(state);
|
|
return [3, 1];
|
|
case 4: return [2];
|
|
}
|
|
});
|
|
}
|
|
return defer((scheduler
|
|
?
|
|
function () { return scheduleIterable(gen(), scheduler); }
|
|
:
|
|
gen));
|
|
}
|
|
//# sourceMappingURL=generate.js.map
|