Skip to content

Commit a674eb0

Browse files
committed
destroy() now removes event handlers too
* fix 2213
1 parent ae5db9c commit a674eb0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Change log
8787
## 8.0.0-dev (TBD)
8888
* 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)
8989
* 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).
90+
* fix: [#2213](https://github.com/gridstack/gridstack.js/issues/2213) `destroy()` now removes event handlers too
9091

9192
## 8.0.0 (2023-04-29)
9293
* package is now ES2020 (TS exported files), webpack all.js still umd (better than commonjs for browsers), still have es5/ files unchanged (for now)

src/gridstack.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ export class GridStack {
894894
*/
895895
public destroy(removeDOM = true): GridStack {
896896
if (!this.el) return; // prevent multiple calls
897+
this.offAll();
897898
this._updateWindowResizeEvent(true);
898899
this.setStatic(true, false); // permanently removes DD but don't set CSS class (we're going away)
899900
this.setAnimation(false);
@@ -1064,6 +1065,12 @@ export class GridStack {
10641065
return this;
10651066
}
10661067

1068+
/** remove all event handlers */
1069+
public offAll(): GridStack {
1070+
Object.keys(this._gsEventHandler).forEach(key => this.off(key));
1071+
return this;
1072+
}
1073+
10671074
/**
10681075
* Removes widget from the grid.
10691076
* @param el widget or selector to modify

0 commit comments

Comments
 (0)