app/composables/useFixtureIO.ts

25 lines
514 B
TypeScript

import { useCounterStore } from '~/stores/counter'
export type AppSnapshot = {
counter: { count: number }
}
export function useFixtureIO() {
const exportAll = (): AppSnapshot => {
const counter = useCounterStore()
return {
counter: { count: counter.count }
}
}
const importAll = (snapshot: AppSnapshot) => {
const counter = useCounterStore()
if (snapshot?.counter) {
counter.$patch({ count: snapshot.counter.count ?? 0 })
}
}
return { exportAll, importAll }
}