Open jamesatjaminit opened 2 years ago
Math.random isn't guaranteed unique either. It seems like a simple counter would be plenty for this.
let last_toast = 0;
function add_toast(...) {
while (last_toast == Date.now()) {}
last_toast = Date.now();
toasts.add({...});
}
I think it should check if a uid is passed before overwriting it I tried passing a uid but it's not taken into account
I think we should use a global counter
I create PR for this, using key instead of uid, auto-generated uuid.v4() or given input
Since the UID of a toast is generated via
Date.now()
generating two toasts quickly after one another causes svelte to throw:Error: Cannot have duplicate keys in a keyed each
. I fixed it in my fork by generating the UID usingMath.random()
which should reduce the collision rate, although I'm not sure if that's how you'd like to fix it.