UNPKG

3.28 kBJavaScriptView Raw
1/**
2 * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
3 * @version v18.1.2
4 * @link http://www.ag-grid.com/
5 * @license MIT
6 */
7"use strict";
8Object.defineProperty(exports, "__esModule", { value: true });
9var eventService_1 = require("../eventService");
10var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
11var utils_1 = require("../utils");
12var BeanStub = (function () {
13 function BeanStub() {
14 this.destroyFunctions = [];
15 this.destroyed = false;
16 }
17 BeanStub.prototype.destroy = function () {
18 this.destroyFunctions.forEach(function (func) { return func(); });
19 this.destroyFunctions.length = 0;
20 this.destroyed = true;
21 this.dispatchEvent({ type: BeanStub.EVENT_DESTROYED });
22 };
23 BeanStub.prototype.addEventListener = function (eventType, listener) {
24 if (!this.localEventService) {
25 this.localEventService = new eventService_1.EventService();
26 }
27 this.localEventService.addEventListener(eventType, listener);
28 };
29 BeanStub.prototype.removeEventListener = function (eventType, listener) {
30 if (this.localEventService) {
31 this.localEventService.removeEventListener(eventType, listener);
32 }
33 };
34 BeanStub.prototype.dispatchEventAsync = function (event) {
35 var _this = this;
36 setTimeout(function () { return _this.dispatchEvent(event); }, 0);
37 };
38 BeanStub.prototype.dispatchEvent = function (event) {
39 if (this.localEventService) {
40 this.localEventService.dispatchEvent(event);
41 }
42 };
43 BeanStub.prototype.addDestroyableEventListener = function (eElement, event, listener) {
44 if (this.destroyed) {
45 return;
46 }
47 if (eElement instanceof HTMLElement) {
48 utils_1._.addSafePassiveEventListener(eElement, event, listener);
49 }
50 else if (eElement instanceof Window) {
51 eElement.addEventListener(event, listener);
52 }
53 else if (eElement instanceof gridOptionsWrapper_1.GridOptionsWrapper) {
54 eElement.addEventListener(event, listener);
55 }
56 else {
57 eElement.addEventListener(event, listener);
58 }
59 this.destroyFunctions.push(function () {
60 if (eElement instanceof HTMLElement) {
61 eElement.removeEventListener(event, listener);
62 }
63 else if (eElement instanceof Window) {
64 eElement.removeEventListener(event, listener);
65 }
66 else if (eElement instanceof gridOptionsWrapper_1.GridOptionsWrapper) {
67 eElement.removeEventListener(event, listener);
68 }
69 else {
70 eElement.removeEventListener(event, listener);
71 }
72 });
73 };
74 BeanStub.prototype.isAlive = function () {
75 return !this.destroyed;
76 };
77 BeanStub.prototype.addDestroyFunc = function (func) {
78 // if we are already destroyed, we execute the func now
79 if (this.isAlive()) {
80 this.destroyFunctions.push(func);
81 }
82 else {
83 func();
84 }
85 };
86 BeanStub.EVENT_DESTROYED = 'destroyed';
87 return BeanStub;
88}());
89exports.BeanStub = BeanStub;