Skip to content

Commit

Permalink
fix: applies change to event listener registration and cleanup (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
ka1ea6 committed Jun 13, 2024
1 parent f5db242 commit 37438bd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ export default class extends Controller {
static classes = ['enter', 'enterFrom', 'enterTo', 'leave', 'leaveFrom', 'leaveTo', 'toggle']

connect() {
document.addEventListener("turbo:before-cache", this.beforeCache.bind(this))
this.boundBeforeCache = this.beforeCache.bind(this)
document.addEventListener('turbo:before-cache', this.boundBeforeCache)
}

disconnect() {
document.removeEventListener("turbo:before-cache", this.beforeCache.bind(this))
document.removeEventListener('turbo:before-cache', this.boundBeforeCache)
}

openValueChanged() {
Expand Down
5 changes: 3 additions & 2 deletions src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ export default class extends Controller {

connect() {
if (this.openValue) this.open()
document.addEventListener("turbo:before-cache", this.beforeCache.bind(this))
this.boundBeforeCache = this.beforeCache.bind(this)
document.addEventListener("turbo:before-cache", this.boundBeforeCache)
}

disconnect() {
document.removeEventListener("turbo:before-cache", this.beforeCache.bind(this))
document.removeEventListener("turbo:before-cache", this.boundBeforeCache)
}

open() {
Expand Down
5 changes: 3 additions & 2 deletions src/slideover.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ export default class extends Controller {

connect() {
if (this.openValue) this.open()
document.addEventListener("turbo:before-cache", this.beforeCache.bind(this))
this.boundBeforeCache = this.beforeCache
document.addEventListener("turbo:before-cache", this.boundBeforeCache)
}

disconnect() {
document.removeEventListener("turbo:before-cache", this.beforeCache.bind(this))
document.removeEventListener("turbo:before-cache", this.boundBeforeCache)
}

open() {
Expand Down

0 comments on commit 37438bd

Please sign in to comment.