expect(spy).toHaveBeenCalledTimes(1)
})
+ it('state can be watched when a ref is given', async () => {
+ const store = useStore()
+ const spy = jest.fn()
+ watch(() => store.name, spy)
+ expect(spy).not.toHaveBeenCalled()
+ const nameRef = ref('Ed')
+ // @ts-expect-error
+ store.$state.name = nameRef
+ await nextTick()
+ expect(spy).toHaveBeenCalledTimes(1)
+ })
+
it('can be given a ref', () => {
const pinia = createPinia()
const store = useStore(pinia)
const setupStore = pinia._e.run(() => {
scope = effectScope()
return scope.run(() => {
- const store = setup()
-
// skip setting up the watcher on HMR
if (!__DEV__ || !hot) {
watch(
)!
}
- return store
+ return setup()
})
})!
}
}
- // TODO: PURE to tree shake?
- const _hmrPayload = markRaw({
+ const _hmrPayload = /*#__PURE__*/ markRaw({
actions: {} as Record<string, any>,
getters: {} as Record<string, Ref>,
state: [] as string[],
const partialStore = {
_p: pinia,
+ // _s: scope,
$id,
$onAction,
$patch,
id = idOrOptions.id
}
- if (__DEV__) {
- // TODO: check duplicated ids
- }
-
function useStore(pinia?: Pinia | null, hot?: Store): Store {
const currentInstance = getCurrentInstance()
pinia =