mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-12 16:44:17 +02:00
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.
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Data from './dom/data'
|
import Data from './dom/data'
|
||||||
|
import EventHandler from './dom/event-handler'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
@@ -29,6 +30,7 @@ class BaseComponent {
|
|||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
Data.remove(this._element, this.constructor.DATA_KEY)
|
Data.remove(this._element, this.constructor.DATA_KEY)
|
||||||
|
EventHandler.off(this._element, `.${this.constructor.DATA_KEY}`)
|
||||||
this._element = null
|
this._element = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -216,8 +216,6 @@ class Carousel extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
EventHandler.off(this._element, EVENT_KEY)
|
|
||||||
|
|
||||||
this._items = null
|
this._items = null
|
||||||
this._config = null
|
this._config = null
|
||||||
this._interval = null
|
this._interval = null
|
||||||
|
@@ -237,7 +237,6 @@ class Dropdown extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
EventHandler.off(this._element, EVENT_KEY)
|
|
||||||
this._menu = null
|
this._menu = null
|
||||||
|
|
||||||
if (this._popper) {
|
if (this._popper) {
|
||||||
|
@@ -187,7 +187,7 @@ class Modal extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
[window, this._element, this._dialog]
|
[window, this._dialog]
|
||||||
.forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))
|
.forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))
|
||||||
|
|
||||||
super.dispose()
|
super.dispose()
|
||||||
|
@@ -156,8 +156,6 @@ class Toast extends BaseComponent {
|
|||||||
this._element.classList.remove(CLASS_NAME_SHOW)
|
this._element.classList.remove(CLASS_NAME_SHOW)
|
||||||
}
|
}
|
||||||
|
|
||||||
EventHandler.off(this._element, EVENT_CLICK_DISMISS)
|
|
||||||
|
|
||||||
super.dispose()
|
super.dispose()
|
||||||
this._config = null
|
this._config = null
|
||||||
}
|
}
|
||||||
|
@@ -215,7 +215,6 @@ class Tooltip extends BaseComponent {
|
|||||||
dispose() {
|
dispose() {
|
||||||
clearTimeout(this._timeout)
|
clearTimeout(this._timeout)
|
||||||
|
|
||||||
EventHandler.off(this._element, this.constructor.EVENT_KEY)
|
|
||||||
EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler)
|
EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler)
|
||||||
|
|
||||||
if (this.tip && this.tip.parentNode) {
|
if (this.tip && this.tip.parentNode) {
|
||||||
|
Reference in New Issue
Block a user