CollectingHandler.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. var __importDefault = (this && this.__importDefault) || function (mod) {
  16. return (mod && mod.__esModule) ? mod : { "default": mod };
  17. };
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. var MultiplexHandler_1 = __importDefault(require("./MultiplexHandler"));
  20. var CollectingHandler = /** @class */ (function (_super) {
  21. __extends(CollectingHandler, _super);
  22. function CollectingHandler(cbs) {
  23. if (cbs === void 0) { cbs = {}; }
  24. var _this = _super.call(this, function (name) {
  25. var _a;
  26. var args = [];
  27. for (var _i = 1; _i < arguments.length; _i++) {
  28. args[_i - 1] = arguments[_i];
  29. }
  30. _this.events.push([name].concat(args));
  31. // @ts-ignore
  32. if (_this._cbs[name])
  33. (_a = _this._cbs)[name].apply(_a, args);
  34. }) || this;
  35. _this._cbs = cbs;
  36. _this.events = [];
  37. return _this;
  38. }
  39. CollectingHandler.prototype.onreset = function () {
  40. this.events = [];
  41. if (this._cbs.onreset)
  42. this._cbs.onreset();
  43. };
  44. CollectingHandler.prototype.restart = function () {
  45. var _a;
  46. if (this._cbs.onreset)
  47. this._cbs.onreset();
  48. for (var i = 0; i < this.events.length; i++) {
  49. var _b = this.events[i], name_1 = _b[0], args = _b.slice(1);
  50. if (!this._cbs[name_1]) {
  51. continue;
  52. }
  53. // @ts-ignore
  54. (_a = this._cbs)[name_1].apply(_a, args);
  55. }
  56. };
  57. return CollectingHandler;
  58. }(MultiplexHandler_1.default));
  59. exports.CollectingHandler = CollectingHandler;