π Is your documentation request related to a problem? Please describe.
I've an store/account.ts module.
Here the relevant part to address my issue. (I'm using Helper functions)
export const state = () => ({
isAuthenticated: false as boolean,
user: {} as any,
)}
export const mutations = mutationTree(state, {
setUser(state, newUser: any) {
console.log('1', newUser)
console.log('2', state.user)
state.isAuthenticated = !!newUser
state.user = newUser
},
and an action that commit setUser mutation
export const actions = actionTree(
{ state, getters, mutations },
{
async load({ commit, dispatch, getters, state }) {
try {
const user = await getAuthenticatedUser()
this.app.$accessor.account.setUser(user)
} catch (error) {
this.app.$accessor.account.setUser(null)
}
},
If inspect the console.log('1', newUser) I have the expected object, but when I want to set in state with the mutation, the state is not updated correctly.
If I inspect the console.log('2', state.user) I see this:
{__ob__: Observer}
__ob__: Observer {value: {β¦}, dep: Dep, vmCount: 0}
__proto__: Object
Can you clarify what's happening here?
I don't think this is an issue, but my mistake in the implementation phase
π Where should you find it?
https://typed-vuex.roe.dev/build
https://typed-vuex.roe.dev/mutations
βΉοΈ Additional context
I provide the store/index.ts here:
import { GetterTree, MutationTree, ActionTree } from 'vuex'
import { getAccessorType } from 'typed-vuex'
import * as module1 from '~/store/module1'
import * as accountModule from '~/store/account'
export const state = () => ({})
export type RootState = ReturnType<typeof state>
export const getters: GetterTree<RootState, RootState> = {}
export const mutations: MutationTree<RootState> = {}
export const actions: ActionTree<RootState, RootState> = {
nuxtServerInit ({ dispatch, commit }) {
console.log(dispatch, commit)
},
}
// TODO: improve types
export const accessorType: any = getAccessorType({
state,
getters,
mutations,
actions,
modules: {
module1,
accountModule
}
})