svelte-toast icon indicating copy to clipboard operation
svelte-toast copied to clipboard

Toast pop callback usage is weird

Open CatchABus opened this issue 3 years ago • 1 comments

// 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')

CatchABus avatar Nov 03 '21 15:11 CatchABus

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 avatar Nov 08 '21 09:11 zerodevx

Fixed by #66 with a clearer way to clear toasts from a particular container.

zerodevx avatar Feb 24 '23 10:02 zerodevx