expect(store.state.a).toBe(false)
})
+ it('store is forced as the context', () => {
+ const store = useStore()
+ expect(store.state.a).toBe(true)
+ store.toggle.call(null)
+ expect(store.state.a).toBe(false)
+ })
+
it('can call other actions', () => {
const store = useStore()
expect(store.state.a).toBe(true)
wrappedActions[actionName] = function() {
setActiveReq(_r)
// eslint-disable-next-line
- return actions[actionName].apply(this, arguments as unknown as any[])
+ return actions[actionName].apply(store, arguments as unknown as any[])
} as StoreWithActions<A>[typeof actionName]
}
// allow actions use other actions
actions?: A & ThisType<A & StoreWithState<Id, S> & StoreWithGetters<S, G>>
}) {
- const { id, state: buildState, getters, actions } = options
+ const { id, state, getters, actions } = options
return function useStore(): Store<Id, S, G, A> {
const req = getActiveReq()
if (!store) {
stores[id] = store = buildStore(
id,
- buildState,
+ state,
getters,
actions,
getInitialState(id)