Skip to content

Commit

Permalink
feat: clear queue observer if queue not visible
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrani committed May 16, 2024
1 parent cde43a6 commit de28543
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/observers/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@ export default class QueueObserver {

const target = document.querySelector('aside[aria-label="Queue"]')

if (!target) return
if (!target) {
this._observer?.disconnect()
this._observer = null
return
}

this._observer = new MutationObserver(this.#mutationHandler)
this._observer.observe(target, { childList: true, subtree: true })
}, 1000)
}

#mutationHandler = (mutationsList) => {
#mutationHandler = mutationsList => {
for (const mutation of mutationsList) {
if (!this.#isAsideQueueView(mutation)) return

if (this._queueObserverTimeout) clearTimeout(this._queueObserverTimeout)
this._queueObserverTimeout = setTimeout(async () => this._queue.refreshQueue(), 1500)
if (this._timeout) clearTimeout(this._timeout)
this._timeout = setTimeout(async () => this._queue.refreshQueue(), 1500)
}
}


#isAsideQueueView(mutation) {
const target = mutation.target
if (target?.localName !== "ul") return false
Expand Down

0 comments on commit de28543

Please sign in to comment.