Skip to content

Commit

Permalink
Merge pull request #199 from joshnuss/fix-write-on-change
Browse files Browse the repository at this point in the history
fix: Only write changes
  • Loading branch information
joshnuss authored Oct 2, 2023
2 parents 9c7611f + 1774f92 commit 34365a9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
2 changes: 0 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export function persisted<T>(key: string, initialValue: T, options?: Options<T>)

if (json) {
set(<T>serializer.parse(json))
} else {
updateStorage(key, initialValue)
}

if (browser) {
Expand Down
2 changes: 1 addition & 1 deletion test/localStorageStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('persisted()', () => {
const value = get(store)

expect(value).toEqual(123)
expect(localStorage.myKey).toEqual('123')
expect(localStorage.myKey).toBeUndefined()
})

test('uses existing value if data already in local storage', () => {
Expand Down

0 comments on commit 34365a9

Please sign in to comment.