Skip to content

Commit

Permalink
馃┕ map store methods before rehydration (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
prazdevs committed Dec 28, 2022
1 parent 682decf commit f71a54f
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions packages/plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ export function createPersistedState(
}),
)

store.$persist = () => {
persistences.forEach((persistence) => {
persistState(store.$state, persistence)
})
}

store.$hydrate = ({ runHooks = true } = {}) => {
persistences.forEach((persistence) => {
const { beforeRestore, afterRestore } = persistence

if (runHooks)
beforeRestore?.(context)

hydrateStore(store, persistence)

if (runHooks)
afterRestore?.(context)
})
}

persistences.forEach((persistence) => {
const { beforeRestore, afterRestore } = persistence

Expand All @@ -116,25 +136,5 @@ export function createPersistedState(
},
)
})

store.$persist = () => {
persistences.forEach((persistence) => {
persistState(store.$state, persistence)
})
}

store.$hydrate = ({ runHooks = true } = {}) => {
persistences.forEach((persistence) => {
const { beforeRestore, afterRestore } = persistence

if (runHooks)
beforeRestore?.(context)

hydrateStore(store, persistence)

if (runHooks)
afterRestore?.(context)
})
}
}
}

0 comments on commit f71a54f

Please sign in to comment.