Description
In the readme, you mention
Should the state be merged at the same level as actions and getters?
I figured we should open a discussion around this π
My 2 cents:
I think we should either scope all things into relevant properties, eg:
store.state.counter
store.getters.doubleCount
store.actions.reset()
or scope none
store.counter // state
store.doubleCount // getter
store.reset // action
Having them all merged in the "root" store might cause naming conflicts between getters and state. However, you could make the argument that having a getter with the exact same name as a property in the state is a fairly bad design decision to begin with. In the case of a naming conflict, the state one should probably overwrite the getter, as getters will often rely on the state value to produce their own value.
A big pro for having them all in the root is that you would be able to do things like
import { useStore } from '@/stores/my-store';
export default createComponent({
setup() {
const { counter, doubleCount, reset } = useStore();
}
});
where you can destructure any of the 'items' in the store.
Is there any specific reason why you decided on putting actions / getters in the root currently @posva?