aboutsummaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2021-04-11 09:54:48 +0300
committerGitHub <[email protected]>2021-04-11 09:54:48 +0300
commit566451230f5c87c3d7515af02995895df610b8ac (patch)
treedd270eb14c1c2d08840f41c4f6571d42ded605c8 /js/src
parentbac0b0c899b8e7fbdbc1ec7fa1ac1c5b847b3c90 (diff)
downloadbootstrap-566451230f5c87c3d7515af02995895df610b8ac.tar.xz
bootstrap-566451230f5c87c3d7515af02995895df610b8ac.zip
Remove element event listeners through base component (#33429)
After some research, I found out that EventHandler saves all the custom events per element using namespace, and is capable of removing handlers using only the element and its namespace (`DATA_KEY`). So, probably is better to utilize the base-component to do the same job.
Diffstat (limited to 'js/src')
-rw-r--r--js/src/base-component.js2
-rw-r--r--js/src/carousel.js2
-rw-r--r--js/src/dropdown.js1
-rw-r--r--js/src/modal.js2
-rw-r--r--js/src/toast.js2
-rw-r--r--js/src/tooltip.js1
6 files changed, 3 insertions, 7 deletions
diff --git a/js/src/base-component.js b/js/src/base-component.js
index 14e13a0eb..77d54faad 100644
--- a/js/src/base-component.js
+++ b/js/src/base-component.js
@@ -6,6 +6,7 @@
*/
import Data from './dom/data'
+import EventHandler from './dom/event-handler'
/**
* ------------------------------------------------------------------------
@@ -29,6 +30,7 @@ class BaseComponent {
dispose() {
Data.remove(this._element, this.constructor.DATA_KEY)
+ EventHandler.off(this._element, `.${this.constructor.DATA_KEY}`)
this._element = null
}
diff --git a/js/src/carousel.js b/js/src/carousel.js
index e336abb1e..ebb0b7b20 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -216,8 +216,6 @@ class Carousel extends BaseComponent {
}
dispose() {
- EventHandler.off(this._element, EVENT_KEY)
-
this._items = null
this._config = null
this._interval = null
diff --git a/js/src/dropdown.js b/js/src/dropdown.js
index 7d5421a56..b126d3196 100644
--- a/js/src/dropdown.js
+++ b/js/src/dropdown.js
@@ -237,7 +237,6 @@ class Dropdown extends BaseComponent {
}
dispose() {
- EventHandler.off(this._element, EVENT_KEY)
this._menu = null
if (this._popper) {
diff --git a/js/src/modal.js b/js/src/modal.js
index dea90ec0a..c6d67ac95 100644
--- a/js/src/modal.js
+++ b/js/src/modal.js
@@ -187,7 +187,7 @@ class Modal extends BaseComponent {
}
dispose() {
- [window, this._element, this._dialog]
+ [window, this._dialog]
.forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))
super.dispose()
diff --git a/js/src/toast.js b/js/src/toast.js
index 01b994e28..5d762b29d 100644
--- a/js/src/toast.js
+++ b/js/src/toast.js
@@ -156,8 +156,6 @@ class Toast extends BaseComponent {
this._element.classList.remove(CLASS_NAME_SHOW)
}
- EventHandler.off(this._element, EVENT_CLICK_DISMISS)
-
super.dispose()
this._config = null
}
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index a66e1ad41..2bfa42fc7 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -215,7 +215,6 @@ class Tooltip extends BaseComponent {
dispose() {
clearTimeout(this._timeout)
- EventHandler.off(this._element, this.constructor.EVENT_KEY)
EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler)
if (this.tip && this.tip.parentNode) {