Skip to content

Commit

Permalink
feat(useToast): allow updating an existing notification (nuxt#1668)
Browse files Browse the repository at this point in the history
  • Loading branch information
noook authored Apr 15, 2024
1 parent 4415d41 commit ed3a3ba
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/runtime/composables/useToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ export function useToast () {
notifications.value = notifications.value.filter((n: Notification) => n.id !== id)
}

function update (id: string, notification: Partial<Notification>) {
const index = notifications.value.findIndex((n: Notification) => n.id === id)
if (index !== -1) {
const previous = notifications.value[index]
notifications.value.splice(index, 1, { ...previous, ...notification })
}
}

return {
add,
remove
remove,
update
}
}

0 comments on commit ed3a3ba

Please sign in to comment.