Skip to content

Commit 3f75bc9

Browse files
committed
Add feature to remove all active toasts
1 parent e8442fd commit 3f75bc9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

docs/App.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ toast.pop()
8585
8686
// Or remove a particular one
8787
const id = toast.push('Yo!')
88-
toast.pop(id)`,
88+
toast.pop(id)
89+
90+
// Or remove all active toasts
91+
toast.pop(0)`,
8992
run: () => {
9093
toast.pop()
9194
}

src/stores.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ const createToast = () => {
1010
return count
1111
}
1212
const pop = id => {
13-
update(n => id ? n.filter(i => i.id !== id) : n.splice(1))
13+
update(n => {
14+
if (n.length === 0 || id === 0) return []
15+
const target = id || Math.max(...n.map(i => i.id))
16+
return n.filter(i => i.id !== target)
17+
})
1418
}
1519
const set = (id, obj) => {
1620
update(n => {

0 commit comments

Comments
 (0)