square / svelte-store

528 stars 36 forks source link

fix: loadAll/reloadAll resolve with up-to-date store values #51

Closed Akolyte01 closed 1 year ago

Akolyte01 commented 1 year ago

This implements couple small changes to loadAll and reloadAll that may potentially break people's workflows.

Consider the scenario

const storeA = writable('initial a');
const storeB = writable();
loadAll([storeA, storeB]).then( // do something);
storeA.set('final a');
storeB.set('final b'); // loadAll resolves at this point

Before this PR, loadAll would resolve to ['initial a', 'final b'] After this PR, loadAll resolves to ['final a', 'final b']

This change lets you more easily assure that you are operating with the most up to date store data.

The second change regards calling loadAll with a single store (not in an array). Previously loadAll(someStore) would resolve to ['store value']. Now it resolves directly to the store value. This better matches behavior elsewhere in the package, where providing a single store input gives you a single store output, such as derived(someStore, ($someStore) => { // do stuff })