From a674eb03a550107bd33641383a4cb8e53054cb8b Mon Sep 17 00:00:00 2001 From: Alain Dumesny Date: Sat, 29 Apr 2023 16:58:17 -0700 Subject: [PATCH] `destroy()` now removes event handlers too * fix 2213 --- doc/CHANGES.md | 1 + src/gridstack.ts | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/doc/CHANGES.md b/doc/CHANGES.md index 5d3f6b810..cb8ed0d0a 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -87,6 +87,7 @@ Change log ## 8.0.0-dev (TBD) * feat: [#2275](https://github.com/gridstack/gridstack.js/issues/2275) `setupDragIn()` now can take an array or elements (in addition to selector string) and optional parent root (for shadow DOM support) * fix: [#2234](https://github.com/gridstack/gridstack.js/issues/2234) `Utils.getElements('1')` (called by removeWidget() and others) now checks for digit 'selector' (becomes an id). +* fix: [#2213](https://github.com/gridstack/gridstack.js/issues/2213) `destroy()` now removes event handlers too ## 8.0.0 (2023-04-29) * package is now ES2020 (TS exported files), webpack all.js still umd (better than commonjs for browsers), still have es5/ files unchanged (for now) diff --git a/src/gridstack.ts b/src/gridstack.ts index 6df6c4b13..a4b6fe28a 100644 --- a/src/gridstack.ts +++ b/src/gridstack.ts @@ -894,6 +894,7 @@ export class GridStack { */ public destroy(removeDOM = true): GridStack { if (!this.el) return; // prevent multiple calls + this.offAll(); this._updateWindowResizeEvent(true); this.setStatic(true, false); // permanently removes DD but don't set CSS class (we're going away) this.setAnimation(false); @@ -1064,6 +1065,12 @@ export class GridStack { return this; } + /** remove all event handlers */ + public offAll(): GridStack { + Object.keys(this._gsEventHandler).forEach(key => this.off(key)); + return this; + } + /** * Removes widget from the grid. * @param el widget or selector to modify