}),
getters: {
upperCaseName: ({ name }) => name.toUpperCase(),
+ composed: (state, { upperCaseName }) =>
+ (upperCaseName.value as string) + ': ok',
},
})()
}
aStore.state.a = 'b'
expect(aStore.fromB.value).toBe('b b')
})
+
+ it('can use other getters', () => {
+ const store = useStore()
+ expect(store.composed.value).toBe('EDUARDO: ok')
+ })
})
computedGetters[getterName] = computed(() => {
setActiveReq(_r)
// eslint-disable-next-line @typescript-eslint/no-use-before-define
- return getters[getterName](state.value)
+ return getters[getterName](state.value, computedGetters)
}) as StoreWithGetters<S, G>[typeof getterName]
}
export type NonNullObject = Record<any, any>
export interface StoreGetter<S extends StateTree, T = any> {
- (state: S): T
+ // TODO: would be nice to be able to define the getters here
+ (state: S, getters: Record<string, Ref<any>>): T
}
type TODO = any
state: S
) => void
-export type StoreReactiveGetters<
- S extends StateTree,
- G extends Record<string, (state: S, getters: any) => any>
-> = {
- [k in keyof G]: G[k] extends (state: S, getters: any) => infer V ? V : never
-}
-
export type StoreWithGetters<
S extends StateTree,
G extends Record<string, StoreGetter<S>>