Open jamesfoster opened 4 years ago
undefined is a valid initial value for a state property, however, this library excludes them from the state object. As such, any computed values which depend on this state do not react when the state is updated. The following line is the culprit:
undefined
https://github.com/championswimmer/vuex-module-decorators/blob/46257b09a8de8e6b615de0837fdc10ff74d85613/src/module/staticGenerators.ts#L13
I have tested the change to this library to allow undefined here and it has the desired effect! The property is correctly reactive as expected!
Example module:
@Module({ dynamic: true, store, name: 'app-state', }) export default class AppState extends VuexModule { drawer?: boolean = undefined; ... }
Is there a way, currently, to support undefined that I'm missing?
One work around is to ensure all properties of your modules are not undefined:
drawer: { value?: boolean } = { value: undefined }
or
drawer: boolean | null = null;
Both of which require a change to the consuming code as they expect undefined. This feels like a hack.
I can create a Pull Request for the change if you want.
Duplicate of #35 ?
undefined
is a valid initial value for a state property, however, this library excludes them from the state object. As such, any computed values which depend on this state do not react when the state is updated. The following line is the culprit:https://github.com/championswimmer/vuex-module-decorators/blob/46257b09a8de8e6b615de0837fdc10ff74d85613/src/module/staticGenerators.ts#L13
I have tested the change to this library to allow
undefined
here and it has the desired effect! The property is correctly reactive as expected!Example module:
Is there a way, currently, to support
undefined
that I'm missing?One work around is to ensure all properties of your modules are not undefined:
or
Both of which require a change to the consuming code as they expect undefined. This feels like a hack.
I can create a Pull Request for the change if you want.