I’m having a hard time understanding how to update my store in the same file in which it’s defined. I have the following store definition:
export const myStore = writable({
myList: [],
myOtherList: []
});
In a later function, say I want to update myList to another list sourceList. I’ve looked at a bunch of the update function examples, and none make any sense to me. What I want to do is something like this (which obviously doesn’t work):
myStore.myList = sourceList
but for the life of me I can’t figure out the appropriate myStore.update() syntax.
>Solution :
In a Svelte file it’s just:
$myStore.myList = sourceList
Without $ syntax you could do:
myStore.update(current => ({ ...current, myList: sourceList }))