ktsn / vuex-class

Binding helpers for Vuex and vue-class-component
MIT License
1.73k stars 86 forks source link

Dynamic namespace #32

Closed andredewaard closed 5 years ago

andredewaard commented 5 years ago

Is there a way to set the namespace dynamically?

For example if i have a component that can gets his data from 2 different modules in the store and i send that namespace by prop.

This is not working obviously.

@Component
export default class Navigation extends Vue {

  @Prop() private namespace!: string;
  @Getter('documents', { namespace: this.namespace }) private documents!: boolean;
}

This works

@Component
export default class Navigation extends Vue {

  @Prop() private namespace!: string;

  private get documents(): any {
    return store.getters[`${this.namespace}/documents`];
  }
}
hkan commented 5 years ago

I think it's technically impossible. Because in current implementation for decorators, you do not have access to the instance. I'm not fully sure though.

ktsn commented 5 years ago

It's impossible and I'm not sure the advantage to do that in vuex-class as it would not infer the this type.