Skip to content

Commit

Permalink
add dispose in base component
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S authored and XhmikosR committed Nov 24, 2020
1 parent 367ff87 commit f7b0067
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 32 deletions.
5 changes: 0 additions & 5 deletions js/src/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ class Alert extends BaseComponent {
this._removeElement(rootElement)
}

dispose() {
Data.removeData(this._element, DATA_KEY)
this._element = null
}

// Private

_getRootElement(element) {
Expand Down
5 changes: 5 additions & 0 deletions js/src/base-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class BaseComponent {
Data.setData(element, this.constructor.DATA_KEY, this)
}

dispose() {
Data.removeData(this._element, this.constructor.DATA_KEY)
this._element = null
}

/** Static */

static getInstance(element) {
Expand Down
5 changes: 0 additions & 5 deletions js/src/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ class Button extends BaseComponent {
this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE))
}

dispose() {
Data.removeData(this._element, DATA_KEY)
this._element = null
}

// Static

static jQueryInterface(config) {
Expand Down
3 changes: 1 addition & 2 deletions js/src/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,11 @@ class Carousel extends BaseComponent {
}

dispose() {
super.dispose()
EventHandler.off(this._element, EVENT_KEY)
Data.removeData(this._element, DATA_KEY)

this._items = null
this._config = null
this._element = null
this._interval = null
this._isPaused = null
this._isSliding = null
Expand Down
4 changes: 1 addition & 3 deletions js/src/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,9 @@ class Collapse extends BaseComponent {
}

dispose() {
Data.removeData(this._element, DATA_KEY)

super.dispose()
this._config = null
this._parent = null
this._element = null
this._triggerArray = null
this._isTransitioning = null
}
Expand Down
3 changes: 1 addition & 2 deletions js/src/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ class Dropdown extends BaseComponent {
}

dispose() {
Data.removeData(this._element, DATA_KEY)
super.dispose()
EventHandler.off(this._element, EVENT_KEY)
this._element = null
this._menu = null
if (this._popper) {
this._popper.destroy()
Expand Down
5 changes: 2 additions & 3 deletions js/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,16 @@ class Modal extends BaseComponent {
[window, this._element, this._dialog]
.forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))

super.dispose()

/**
* `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API`
* Do not move `document` in `htmlElements` array
* It will remove `EVENT_CLICK_DATA_API` event that should remain
*/
EventHandler.off(document, EVENT_FOCUSIN)

Data.removeData(this._element, DATA_KEY)

this._config = null
this._element = null
this._dialog = null
this._backdrop = null
this._isShown = null
Expand Down
3 changes: 1 addition & 2 deletions js/src/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ class ScrollSpy extends BaseComponent {
}

dispose() {
Data.removeData(this._element, DATA_KEY)
super.dispose()
EventHandler.off(this._scrollElement, EVENT_KEY)

this._element = null
this._scrollElement = null
this._config = null
this._selector = null
Expand Down
5 changes: 0 additions & 5 deletions js/src/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ class Tab extends BaseComponent {
}
}

dispose() {
Data.removeData(this._element, DATA_KEY)
this._element = null
}

// Private

_activate(element, container, callback) {
Expand Down
3 changes: 1 addition & 2 deletions js/src/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ class Toast extends BaseComponent {
}

EventHandler.off(this._element, EVENT_CLICK_DISMISS)
Data.removeData(this._element, DATA_KEY)

this._element = null
super.dispose()
this._config = null
}

Expand Down
4 changes: 1 addition & 3 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ class Tooltip extends BaseComponent {
dispose() {
clearTimeout(this._timeout)

Data.removeData(this._element, this.constructor.DATA_KEY)

EventHandler.off(this._element, this.constructor.EVENT_KEY)
EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler)

Expand All @@ -245,9 +243,9 @@ class Tooltip extends BaseComponent {
}

this._popper = null
this._element = null
this.config = null
this.tip = null
super.dispose()
}

show() {
Expand Down

0 comments on commit f7b0067

Please sign in to comment.