generate.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. "use strict";
  2. var __generator = (this && this.__generator) || function (thisArg, body) {
  3. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  4. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  5. function verb(n) { return function (v) { return step([n, v]); }; }
  6. function step(op) {
  7. if (f) throw new TypeError("Generator is already executing.");
  8. while (_) try {
  9. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  10. if (y = 0, t) op = [op[0] & 2, t.value];
  11. switch (op[0]) {
  12. case 0: case 1: t = op; break;
  13. case 4: _.label++; return { value: op[1], done: false };
  14. case 5: _.label++; y = op[1]; op = [0]; continue;
  15. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  16. default:
  17. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  18. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  19. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  20. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  21. if (t[2]) _.ops.pop();
  22. _.trys.pop(); continue;
  23. }
  24. op = body.call(thisArg, _);
  25. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  26. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  27. }
  28. };
  29. Object.defineProperty(exports, "__esModule", { value: true });
  30. exports.generate = void 0;
  31. var identity_1 = require("../util/identity");
  32. var isScheduler_1 = require("../util/isScheduler");
  33. var defer_1 = require("./defer");
  34. var scheduleIterable_1 = require("../scheduled/scheduleIterable");
  35. function generate(initialStateOrOptions, condition, iterate, resultSelectorOrScheduler, scheduler) {
  36. var _a, _b;
  37. var resultSelector;
  38. var initialState;
  39. if (arguments.length === 1) {
  40. (_a = initialStateOrOptions, initialState = _a.initialState, condition = _a.condition, iterate = _a.iterate, _b = _a.resultSelector, resultSelector = _b === void 0 ? identity_1.identity : _b, scheduler = _a.scheduler);
  41. }
  42. else {
  43. initialState = initialStateOrOptions;
  44. if (!resultSelectorOrScheduler || isScheduler_1.isScheduler(resultSelectorOrScheduler)) {
  45. resultSelector = identity_1.identity;
  46. scheduler = resultSelectorOrScheduler;
  47. }
  48. else {
  49. resultSelector = resultSelectorOrScheduler;
  50. }
  51. }
  52. function gen() {
  53. var state;
  54. return __generator(this, function (_a) {
  55. switch (_a.label) {
  56. case 0:
  57. state = initialState;
  58. _a.label = 1;
  59. case 1:
  60. if (!(!condition || condition(state))) return [3, 4];
  61. return [4, resultSelector(state)];
  62. case 2:
  63. _a.sent();
  64. _a.label = 3;
  65. case 3:
  66. state = iterate(state);
  67. return [3, 1];
  68. case 4: return [2];
  69. }
  70. });
  71. }
  72. return defer_1.defer((scheduler
  73. ?
  74. function () { return scheduleIterable_1.scheduleIterable(gen(), scheduler); }
  75. :
  76. gen));
  77. }
  78. exports.generate = generate;
  79. //# sourceMappingURL=generate.js.map