Toast pop callback usage is weird
CatchABus opened this issue · 2 comments
CatchABus commented
// Remove all toasts from "new" container
toast.pop((i) => i.target !== 'new')
I believe this functionality is contradicting itself.
Callback should delete toasts that meet the condition instead.
At first look, if comment wasn't there, one would parse this line of code as Pop all toasts whose target is NOT new
.
The following approach would be more understandable.
// Remove all toasts from "new" container
toast.pop((i) => i.target === 'new')
zerodevx commented
Hey, thanks for the feedback - I agree that it's misleading. The API should be cleaned up by the next major release so it's more intuitive. Internally, when the pop()
method detects that the input is a filter function, it simply runs it against the store. So:
toast.pop(i => i.target !== 'new')
is actually equivalent to:
import { toast } from '@zerodevx/svelte-toast'
$toast = $toast.filter(i => i.target !== 'new')
Hope this gives some context.
zerodevx commented
Fixed by #66 with a clearer way to clear toasts from a particular container.