Skip to content

Commit

Permalink
馃挜 remove overwrite option (never worked)
Browse files Browse the repository at this point in the history
  • Loading branch information
prazdevs committed Mar 5, 2022
1 parent 6d18bf7 commit b88713c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
11 changes: 1 addition & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ export interface PersistedStateOptions {
*/
paths?: Array<string>

/**
* Overwrite initial state (patch otherwise).
* @default false
*/
overwrite?: boolean

/**
* Serializer to use
*/
Expand Down Expand Up @@ -89,7 +83,6 @@ export default function PiniaPersistState(context: PiniaPluginContext): void {
storage = localStorage,
key = store.$id,
paths = null,
overwrite = false,
beforeRestore = null,
afterRestore = null,
serializer = {
Expand All @@ -103,9 +96,7 @@ export default function PiniaPersistState(context: PiniaPluginContext): void {
try {
const fromStorage = storage.getItem(key)
if (fromStorage) {
const storageState = serializer.deserialize(fromStorage)
if (overwrite) store.$state = storageState
else store.$patch(storageState)
store.$patch(serializer.deserialize(fromStorage))
}
} catch (_error) {}

Expand Down
20 changes: 0 additions & 20 deletions tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,6 @@ describe('w/ storage', () => {
})
})

describe('w/ overwrite', () => {
const useStore = defineStore(key, {
state: () => ({ lorem: 'ipsum' }),
persist: { overwrite: true },
})

it('overwrites store from storage', async () => {
//* arrange
initializeLocalStorage(key, { lorem: 'dolor sit amet' })

//* act
await nextTick()
const store = useStore()

//* assert
expect(store.lorem).toEqual('dolor sit amet')
expect(localStorage.getItem).toHaveBeenCalledWith(key)
})
})

describe('w/ hooks', () => {
const beforeRestore = vi.fn(ctx => {
ctx.store.before = 'before'
Expand Down

0 comments on commit b88713c

Please sign in to comment.