mirror of https://github.com/twbs/bootstrap.git
add dispose in base component
This commit is contained in:
parent
51a208f119
commit
9eb9d02084
|
|
@ -69,11 +69,6 @@ class Alert extends BaseComponent {
|
||||||
this._removeElement(rootElement)
|
this._removeElement(rootElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
|
||||||
Data.removeData(this._element, DATA_KEY)
|
|
||||||
this._element = null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
_getRootElement(element) {
|
_getRootElement(element) {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,11 @@ class BaseComponent {
|
||||||
Data.setData(element, this.constructor.DATA_KEY, this)
|
Data.setData(element, this.constructor.DATA_KEY, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispose() {
|
||||||
|
Data.removeData(this._element, this.constructor.DATA_KEY)
|
||||||
|
this._element = null
|
||||||
|
}
|
||||||
|
|
||||||
/** Static */
|
/** Static */
|
||||||
|
|
||||||
static getInstance(element) {
|
static getInstance(element) {
|
||||||
|
|
|
||||||
|
|
@ -52,11 +52,6 @@ class Button extends BaseComponent {
|
||||||
this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE))
|
this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE))
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
|
||||||
Data.removeData(this._element, DATA_KEY)
|
|
||||||
this._element = null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Static
|
// Static
|
||||||
|
|
||||||
static jQueryInterface(config) {
|
static jQueryInterface(config) {
|
||||||
|
|
|
||||||
|
|
@ -224,12 +224,11 @@ class Carousel extends BaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
|
super.dispose()
|
||||||
EventHandler.off(this._element, EVENT_KEY)
|
EventHandler.off(this._element, EVENT_KEY)
|
||||||
Data.removeData(this._element, DATA_KEY)
|
|
||||||
|
|
||||||
this._items = null
|
this._items = null
|
||||||
this._config = null
|
this._config = null
|
||||||
this._element = null
|
|
||||||
this._interval = null
|
this._interval = null
|
||||||
this._isPaused = null
|
this._isPaused = null
|
||||||
this._isSliding = null
|
this._isSliding = null
|
||||||
|
|
|
||||||
|
|
@ -272,11 +272,9 @@ class Collapse extends BaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
Data.removeData(this._element, DATA_KEY)
|
super.dispose()
|
||||||
|
|
||||||
this._config = null
|
this._config = null
|
||||||
this._parent = null
|
this._parent = null
|
||||||
this._element = null
|
|
||||||
this._triggerArray = null
|
this._triggerArray = null
|
||||||
this._isTransitioning = null
|
this._isTransitioning = null
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -235,9 +235,8 @@ class Dropdown extends BaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
Data.removeData(this._element, DATA_KEY)
|
super.dispose()
|
||||||
EventHandler.off(this._element, EVENT_KEY)
|
EventHandler.off(this._element, EVENT_KEY)
|
||||||
this._element = null
|
|
||||||
this._menu = null
|
this._menu = null
|
||||||
if (this._popper) {
|
if (this._popper) {
|
||||||
this._popper.destroy()
|
this._popper.destroy()
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,8 @@ class Modal extends BaseComponent {
|
||||||
[window, this._element, this._dialog]
|
[window, this._element, this._dialog]
|
||||||
.forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))
|
.forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))
|
||||||
|
|
||||||
|
super.dispose()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API`
|
* `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API`
|
||||||
* Do not move `document` in `htmlElements` array
|
* Do not move `document` in `htmlElements` array
|
||||||
|
|
@ -214,10 +216,7 @@ class Modal extends BaseComponent {
|
||||||
*/
|
*/
|
||||||
EventHandler.off(document, EVENT_FOCUSIN)
|
EventHandler.off(document, EVENT_FOCUSIN)
|
||||||
|
|
||||||
Data.removeData(this._element, DATA_KEY)
|
|
||||||
|
|
||||||
this._config = null
|
this._config = null
|
||||||
this._element = null
|
|
||||||
this._dialog = null
|
this._dialog = null
|
||||||
this._backdrop = null
|
this._backdrop = null
|
||||||
this._isShown = null
|
this._isShown = null
|
||||||
|
|
|
||||||
|
|
@ -146,10 +146,9 @@ class ScrollSpy extends BaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
Data.removeData(this._element, DATA_KEY)
|
super.dispose()
|
||||||
EventHandler.off(this._scrollElement, EVENT_KEY)
|
EventHandler.off(this._scrollElement, EVENT_KEY)
|
||||||
|
|
||||||
this._element = null
|
|
||||||
this._scrollElement = null
|
this._scrollElement = null
|
||||||
this._config = null
|
this._config = null
|
||||||
this._selector = null
|
this._selector = null
|
||||||
|
|
|
||||||
|
|
@ -126,11 +126,6 @@ class Tab extends BaseComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
|
||||||
Data.removeData(this._element, DATA_KEY)
|
|
||||||
this._element = null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
_activate(element, container, callback) {
|
_activate(element, container, callback) {
|
||||||
|
|
|
||||||
|
|
@ -165,9 +165,8 @@ class Toast extends BaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
EventHandler.off(this._element, EVENT_CLICK_DISMISS)
|
EventHandler.off(this._element, EVENT_CLICK_DISMISS)
|
||||||
Data.removeData(this._element, DATA_KEY)
|
|
||||||
|
|
||||||
this._element = null
|
super.dispose()
|
||||||
this._config = null
|
this._config = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -229,8 +229,6 @@ class Tooltip extends BaseComponent {
|
||||||
dispose() {
|
dispose() {
|
||||||
clearTimeout(this._timeout)
|
clearTimeout(this._timeout)
|
||||||
|
|
||||||
Data.removeData(this._element, this.constructor.DATA_KEY)
|
|
||||||
|
|
||||||
EventHandler.off(this._element, this.constructor.EVENT_KEY)
|
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)
|
||||||
|
|
||||||
|
|
@ -247,9 +245,9 @@ class Tooltip extends BaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._popper = null
|
this._popper = null
|
||||||
this._element = null
|
|
||||||
this.config = null
|
this.config = null
|
||||||
this.tip = null
|
this.tip = null
|
||||||
|
super.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
show() {
|
show() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue