pstanoev / simple-svelte-autocomplete

Simple Autocomplete / typeahead component for Svelte
http://simple-svelte-autocomplete.surge.sh/
MIT License
469 stars 79 forks source link

Fix reactivity for onCreate #107

Closed v1ack closed 3 years ago

v1ack commented 3 years ago

Fixes #102 onCreate with store doesn't work because we use items before it's updated with onCreate

You used a hack with unshift in your example

function handleCreate(newColor) {
  toCreate = 'Creating ' + newColor; 
  colors.unshift(newColor);
  colors = colors;
  return newColor
}

colors stays the same object (same link), but it doesn't work with store or svelte-way reactive array update (like colors = [newColor, ...colors])

So, we need to wait for reactive items update before finding created item

pstanoev commented 3 years ago

Thanks for the code. Currently I don't think I will merge this since reusing the items an alternative. I don't want to introduce a bunch of async functions only for this. The creatable support in the whole component is shaky, I might rewrite it at some point.