-import { describe, beforeEach, it, expect } from 'vitest'
+import { describe, beforeEach, it, expect, vi } from 'vitest'
import { computed, reactive, ref, ToRefs } from 'vue'
import { createPinia, defineStore, setActivePinia, storeToRefs } from '../src'
import { set } from 'vue-demi'
expect(double.value).toEqual(1)
})
+ it('does not trigger getters', () => {
+ const n = ref(0)
+ const spy = vi.fn(() => n.value * 2)
+ const store = defineStore('a', () => {
+ const double = computed(spy)
+ return { n, double }
+ })()
+
+ expect(spy).toHaveBeenCalledTimes(0)
+ storeToRefs(store)
+ expect(spy).toHaveBeenCalledTimes(0)
+ })
+
tds(() => {
const store1 = defineStore('a', () => {
const n = ref(0)
import {
+ computed,
ComputedRef,
isReactive,
isRef,
const refs = {} as StoreToRefs<SS>
for (const key in rawStore) {
const value = rawStore[key]
- if (isRef(value) || isReactive(value)) {
+ // There is no native method to check for a computed
+ // https://github.com/vuejs/core/pull/4165
+ if (value.effect) {
+ // @ts-expect-error: too hard to type correctly
+ refs[key] =
+ // ...
+ computed({
+ get: () => store[key],
+ set(value) {
+ store[key] = value
+ },
+ })
+ } else if (isRef(value) || isReactive(value)) {
// @ts-expect-error: the key is state or getter
refs[key] =
// ---