Closed joshnuss closed 8 months ago
This fixes a bug where the initial value set incorrectly. Closes #231
Previously, it only read the initial value inside store's closure:
writable(initialValue, set => { // read from storage *inside* closure const json = storage.getItem(key) const existingValue = JSON.parse(parsedValue) // ... })
But that closure is only called on first get.
Instead, the initial read should happen before the store is even created:
// read from storage **outside** closure, before initializing store const json = storage.getItem(key) const initialOrExisting = json ? JSON.parse(json) : initialValue writable(initialOrExisting, set => { // ... })
:tada: This PR is included in version 0.8.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
This fixes a bug where the initial value set incorrectly. Closes #231
Previously, it only read the initial value inside store's closure:
But that closure is only called on first get.
Instead, the initial read should happen before the store is even created: