generate.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { __generator } from "tslib";
  2. import { identity } from '../util/identity';
  3. import { isScheduler } from '../util/isScheduler';
  4. import { defer } from './defer';
  5. import { scheduleIterable } from '../scheduled/scheduleIterable';
  6. export function generate(initialStateOrOptions, condition, iterate, resultSelectorOrScheduler, scheduler) {
  7. var _a, _b;
  8. var resultSelector;
  9. var initialState;
  10. if (arguments.length === 1) {
  11. (_a = initialStateOrOptions, initialState = _a.initialState, condition = _a.condition, iterate = _a.iterate, _b = _a.resultSelector, resultSelector = _b === void 0 ? identity : _b, scheduler = _a.scheduler);
  12. }
  13. else {
  14. initialState = initialStateOrOptions;
  15. if (!resultSelectorOrScheduler || isScheduler(resultSelectorOrScheduler)) {
  16. resultSelector = identity;
  17. scheduler = resultSelectorOrScheduler;
  18. }
  19. else {
  20. resultSelector = resultSelectorOrScheduler;
  21. }
  22. }
  23. function gen() {
  24. var state;
  25. return __generator(this, function (_a) {
  26. switch (_a.label) {
  27. case 0:
  28. state = initialState;
  29. _a.label = 1;
  30. case 1:
  31. if (!(!condition || condition(state))) return [3, 4];
  32. return [4, resultSelector(state)];
  33. case 2:
  34. _a.sent();
  35. _a.label = 3;
  36. case 3:
  37. state = iterate(state);
  38. return [3, 1];
  39. case 4: return [2];
  40. }
  41. });
  42. }
  43. return defer((scheduler
  44. ?
  45. function () { return scheduleIterable(gen(), scheduler); }
  46. :
  47. gen));
  48. }
  49. //# sourceMappingURL=generate.js.map