Skip to content

Commit

Permalink
fix: remove item from storage when no longer useful (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrani authored Nov 7, 2023
1 parent 1dd1ea2 commit 6c5cda3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ window.addEventListener('message', async (event) => {
break

case 'storage.delete':
response = await removeState(payload.key)
sendEventToPage({ eventType: 'storage.delete.response', detail: response })
await removeState(payload.key)
break

case 'storage.populate':
Expand Down
28 changes: 23 additions & 5 deletions src/stores/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,31 @@ class DataStore {
return this.#cache.getKey(id)
}

async saveTrack({ id, value }) {
const response = await this.#dispatcher.sendEvent({
eventType: 'storage.set',
detail: { key: id, values: value },
async removeTrack(id) {
await this.#dispatcher.sendEvent({
eventType: 'storage.delete',
detail: { key: id },
})
}

this.#cache.update({ key: id, value: response })
shouldRemoveTrack({ isSkipped, playbackRate = '1', isSnip }) {
if (isSkipped || isSnip || playbackRate != '1') return false

return true
}

async saveTrack({ id, value }) {
let response
if (this.shouldRemoveTrack(value)) {
this.removeTrack(id)
} else {
response = await this.#dispatcher.sendEvent({
eventType: 'storage.set',
detail: { key: id, values: value },
})
}

this.#cache.update({ key: id, value: response ?? value })
return this.#cache.getKey(id)
}

Expand Down

0 comments on commit 6c5cda3

Please sign in to comment.