]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Refactor: move disposing properties into the base class (#33740)
authorGeoSot <geo.sotis@gmail.com>
Tue, 11 May 2021 06:04:42 +0000 (09:04 +0300)
committerGitHub <noreply@github.com>
Tue, 11 May 2021 06:04:42 +0000 (09:04 +0300)
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 .

js/src/base-component.js
js/src/carousel.js
js/src/collapse.js
js/src/dropdown.js
js/src/modal.js
js/src/offcanvas.js
js/src/scrollspy.js
js/src/toast.js
js/src/tooltip.js

index 7d2a5b1e8797ccc02f8bd808f01605315e47d07e..588a59d756cfe30392886741f6ce82039124623b 100644 (file)
@@ -36,7 +36,10 @@ class BaseComponent {
   dispose() {
     Data.remove(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) {
index 2f5cd9de952be5d1cf07424b35bccb7bfe9bf91b..92733637e9b0d48d14b6cad49c1f32b397f16b6d 100644 (file)
@@ -213,18 +213,6 @@ class Carousel extends BaseComponent {
     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
 
   _getConfig(config) {
index bd3846e0536f1f954dd0c306926b1ded87f4be8c..0d1b91be55cf6e1ec519af9562bf4d1ffb7e1209 100644 (file)
@@ -253,14 +253,6 @@ class Collapse extends BaseComponent {
     this._isTransitioning = isTransitioning
   }
 
-  dispose() {
-    super.dispose()
-    this._config = null
-    this._parent = null
-    this._triggerArray = null
-    this._isTransitioning = null
-  }
-
   // Private
 
   _getConfig(config) {
index bb2d01c274c324683a572ebfb2c8abe0f5810727..8bd3f01e70519189e91a2706fd902dbf18d567e5 100644 (file)
@@ -217,11 +217,8 @@ class Dropdown extends BaseComponent {
   }
 
   dispose() {
-    this._menu = null
-
     if (this._popper) {
       this._popper.destroy()
-      this._popper = null
     }
 
     super.dispose()
index 6701c896f77eefdf284441e79f99aa01db6af292..44f2a0cbb28c1cb240990e067fcc78bfd6464d7c 100644 (file)
@@ -183,6 +183,7 @@ class Modal extends BaseComponent {
     [window, this._dialog]
       .forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))
 
+    this._backdrop.dispose()
     super.dispose()
 
     /**
@@ -191,14 +192,6 @@ class Modal extends BaseComponent {
      * It will remove `EVENT_CLICK_DATA_API` event that should remain
      */
     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() {
index 68f8e814225db88d034cdb27d675a9a52b372d3a..8ddb776b1f3b332dd2ea67247bc82aead00ce4a8 100644 (file)
@@ -162,9 +162,6 @@ class Offcanvas extends BaseComponent {
     this._backdrop.dispose()
     super.dispose()
     EventHandler.off(document, EVENT_FOCUSIN)
-
-    this._config = null
-    this._backdrop = null
   }
 
   // Private
index 0f59696602a5279a2c1cbc01f4318c9a3151eaac..7c59dabcff0f000012fe288267ef96c2fe27eeb5 100644 (file)
@@ -137,16 +137,8 @@ class ScrollSpy extends BaseComponent {
   }
 
   dispose() {
-    super.dispose()
     EventHandler.off(this._scrollElement, EVENT_KEY)
-
-    this._scrollElement = null
-    this._config = null
-    this._selector = null
-    this._offsets = null
-    this._targets = null
-    this._activeTarget = null
-    this._scrollHeight = null
+    super.dispose()
   }
 
   // Private
index 94a9084ce5273ea3aab141fadeb53f15c6f83edf..cf869cd5a3039ca18d6420e4d7b1f5d21a71dd14 100644 (file)
@@ -144,7 +144,6 @@ class Toast extends BaseComponent {
     }
 
     super.dispose()
-    this._config = null
   }
 
   // Private
index 65eb7a11ca02b89055d72b5a7f0ebd19eabf6a83..7226d3123490d049797b5354bd5d9249995bc3df 100644 (file)
@@ -219,17 +219,10 @@ class Tooltip extends BaseComponent {
       this.tip.parentNode.removeChild(this.tip)
     }
 
-    this._isEnabled = null
-    this._timeout = null
-    this._hoverState = null
-    this._activeTrigger = null
     if (this._popper) {
       this._popper.destroy()
     }
 
-    this._popper = null
-    this.config = null
-    this.tip = null
     super.dispose()
   }