mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-12 00:24:03 +02:00
Refactor: move disposing properties into the base class (#33740)
Moves more functionality to `base-component`, transferring the responsibility of disposal to parent class. Each component, dusting disposal, sets its protected properties to `null`. So the same can be done in one place for all children components .
This commit is contained in:
@@ -36,7 +36,10 @@ 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}`)
|
EventHandler.off(this._element, `.${this.constructor.DATA_KEY}`)
|
||||||
this._element = null
|
|
||||||
|
Object.getOwnPropertyNames(this).forEach(propertyName => {
|
||||||
|
this[propertyName] = null
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_queueCallback(callback, element, isAnimated = true) {
|
_queueCallback(callback, element, isAnimated = true) {
|
||||||
|
@@ -213,18 +213,6 @@ class Carousel extends BaseComponent {
|
|||||||
this._slide(order, this._items[index])
|
this._slide(order, this._items[index])
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
|
||||||
this._items = null
|
|
||||||
this._config = null
|
|
||||||
this._interval = null
|
|
||||||
this._isPaused = null
|
|
||||||
this._isSliding = null
|
|
||||||
this._activeElement = null
|
|
||||||
this._indicatorsElement = null
|
|
||||||
|
|
||||||
super.dispose()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
_getConfig(config) {
|
_getConfig(config) {
|
||||||
|
@@ -253,14 +253,6 @@ class Collapse extends BaseComponent {
|
|||||||
this._isTransitioning = isTransitioning
|
this._isTransitioning = isTransitioning
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
|
||||||
super.dispose()
|
|
||||||
this._config = null
|
|
||||||
this._parent = null
|
|
||||||
this._triggerArray = null
|
|
||||||
this._isTransitioning = null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
_getConfig(config) {
|
_getConfig(config) {
|
||||||
|
@@ -217,11 +217,8 @@ class Dropdown extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
this._menu = null
|
|
||||||
|
|
||||||
if (this._popper) {
|
if (this._popper) {
|
||||||
this._popper.destroy()
|
this._popper.destroy()
|
||||||
this._popper = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.dispose()
|
super.dispose()
|
||||||
|
@@ -183,6 +183,7 @@ class Modal extends BaseComponent {
|
|||||||
[window, this._dialog]
|
[window, this._dialog]
|
||||||
.forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))
|
.forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))
|
||||||
|
|
||||||
|
this._backdrop.dispose()
|
||||||
super.dispose()
|
super.dispose()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,14 +192,6 @@ class Modal extends BaseComponent {
|
|||||||
* It will remove `EVENT_CLICK_DATA_API` event that should remain
|
* It will remove `EVENT_CLICK_DATA_API` event that should remain
|
||||||
*/
|
*/
|
||||||
EventHandler.off(document, EVENT_FOCUSIN)
|
EventHandler.off(document, EVENT_FOCUSIN)
|
||||||
|
|
||||||
this._config = null
|
|
||||||
this._dialog = null
|
|
||||||
this._backdrop.dispose()
|
|
||||||
this._backdrop = null
|
|
||||||
this._isShown = null
|
|
||||||
this._ignoreBackdropClick = null
|
|
||||||
this._isTransitioning = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleUpdate() {
|
handleUpdate() {
|
||||||
|
@@ -162,9 +162,6 @@ class Offcanvas extends BaseComponent {
|
|||||||
this._backdrop.dispose()
|
this._backdrop.dispose()
|
||||||
super.dispose()
|
super.dispose()
|
||||||
EventHandler.off(document, EVENT_FOCUSIN)
|
EventHandler.off(document, EVENT_FOCUSIN)
|
||||||
|
|
||||||
this._config = null
|
|
||||||
this._backdrop = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
@@ -137,16 +137,8 @@ class ScrollSpy extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
super.dispose()
|
|
||||||
EventHandler.off(this._scrollElement, EVENT_KEY)
|
EventHandler.off(this._scrollElement, EVENT_KEY)
|
||||||
|
super.dispose()
|
||||||
this._scrollElement = null
|
|
||||||
this._config = null
|
|
||||||
this._selector = null
|
|
||||||
this._offsets = null
|
|
||||||
this._targets = null
|
|
||||||
this._activeTarget = null
|
|
||||||
this._scrollHeight = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
@@ -144,7 +144,6 @@ class Toast extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
super.dispose()
|
super.dispose()
|
||||||
this._config = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
@@ -219,17 +219,10 @@ class Tooltip extends BaseComponent {
|
|||||||
this.tip.parentNode.removeChild(this.tip)
|
this.tip.parentNode.removeChild(this.tip)
|
||||||
}
|
}
|
||||||
|
|
||||||
this._isEnabled = null
|
|
||||||
this._timeout = null
|
|
||||||
this._hoverState = null
|
|
||||||
this._activeTrigger = null
|
|
||||||
if (this._popper) {
|
if (this._popper) {
|
||||||
this._popper.destroy()
|
this._popper.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
this._popper = null
|
|
||||||
this.config = null
|
|
||||||
this.tip = null
|
|
||||||
super.dispose()
|
super.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user