CollectingHandler.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __spreadArray = (this && this.__spreadArray) || function (to, from) {
  18. for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
  19. to[j] = from[i];
  20. return to;
  21. };
  22. var __importDefault = (this && this.__importDefault) || function (mod) {
  23. return (mod && mod.__esModule) ? mod : { "default": mod };
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.CollectingHandler = void 0;
  27. var MultiplexHandler_1 = __importDefault(require("./MultiplexHandler"));
  28. var CollectingHandler = /** @class */ (function (_super) {
  29. __extends(CollectingHandler, _super);
  30. function CollectingHandler(cbs) {
  31. if (cbs === void 0) { cbs = {}; }
  32. var _this = _super.call(this, function (name) {
  33. var _a;
  34. var args = [];
  35. for (var _i = 1; _i < arguments.length; _i++) {
  36. args[_i - 1] = arguments[_i];
  37. }
  38. _this.events.push(__spreadArray([name], args));
  39. (_a = _this.cbs[name]) === null || _a === void 0 ? void 0 : _a.apply(void 0, args);
  40. }) || this;
  41. _this.cbs = cbs;
  42. _this.events = [];
  43. return _this;
  44. }
  45. CollectingHandler.prototype.onreset = function () {
  46. var _a, _b;
  47. this.events = [];
  48. (_b = (_a = this.cbs).onreset) === null || _b === void 0 ? void 0 : _b.call(_a);
  49. };
  50. CollectingHandler.prototype.restart = function () {
  51. var _a, _b, _c;
  52. (_b = (_a = this.cbs).onreset) === null || _b === void 0 ? void 0 : _b.call(_a);
  53. for (var _i = 0, _d = this.events; _i < _d.length; _i++) {
  54. var _e = _d[_i], name_1 = _e[0], args = _e.slice(1);
  55. (_c = this.cbs[name_1]) === null || _c === void 0 ? void 0 : _c.apply(void 0, args);
  56. }
  57. };
  58. return CollectingHandler;
  59. }(MultiplexHandler_1.default));
  60. exports.CollectingHandler = CollectingHandler;