Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

fix:modify persistence doesn't work well when using multiple pinia #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PiniaPluginContext } from 'pinia'

import { PiniaPluginContext } from 'pinia'
import nextTick from 'vue'
export interface PersistStrategy {
key?: string;
storage?: Storage;
Expand Down Expand Up @@ -36,7 +37,7 @@ export const updateStorage = (strategy: PersistStrategy, store: Store) => {
}
}

export default ({ options, store }: PiniaPluginContext): void => {
export default async ({ options, store }: PiniaPluginContext): Promise<void> => {
if (options.persist?.enabled) {
const defaultStrat: PersistStrategy[] = [{
key: store.$id,
Expand All @@ -55,7 +56,7 @@ export default ({ options, store }: PiniaPluginContext): void => {
updateStorage(strategy, store)
}
})

await nextTick()
store.$subscribe(() => {
strategies.forEach((strategy) => {
updateStorage(strategy, store)
Expand Down