-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
I am trying to call a getter with a mutation, and it seems not to work:
import { createModule, createProxy, mutation, action } from 'vuex-class-component'
import { Investigation, InvestigationId, InvestigationsState } from './types'
const VuexModule = createModule({
namespaced: 'investigations'
})
export class Investigations extends VuexModule implements InvestigationsState {
investigations: Investigation[] = []
currentInvestigationIndex = -1
get current (): Investigation | undefined {
return this.currentInvestigationIndex >= 0 ? this.investigations[this.currentInvestigationIndex] : undefined
}
get id () {
return (id: InvestigationId): Investigation | undefined => this.investigations.find(i => i.id === id)
}
@mutation
changeSomething ({ investigationId, thing }: { investigationId: InvestigationId, thing: string }): void {
// ERROR: this.id is not a function
const investigation = investigationId ? this.id(investigationId) : this.current
// Do stuff
}
}I can work around this by using a proxy within the mutation:
const me = createProxy(this.$store, Investigations)
const investigation = investigationId ? me.id(investigationId) : me.currentBut I thought that this could have been done at a higher level.
Am I missing something?
Metadata
Metadata
Assignees
Labels
No labels