Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How set a sub-property using call() ? #112

Closed
giuseppe-esposito-87 opened this issue Sep 9, 2020 · 2 comments
Closed

How set a sub-property using call() ? #112

giuseppe-esposito-87 opened this issue Sep 9, 2020 · 2 comments

Comments

@giuseppe-esposito-87
Copy link

giuseppe-esposito-87 commented Sep 9, 2020

Hi,

I've a simple a store with some nested properties, such as

const state = {
  prop1: true,
  ...
  nestedProperties: { subproperty1: true }
};

const mutations = make.mutations(state);
const actions = make.actions(state);
const getters = make.getters(state);

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
};

How can I use call() helper in a component to set "subproperty1" value? I've unsuccessfully tried various combination to define it, such as:

  methods: {
    setSubProp: call("myModule/setNestedProperties@subproperty1")
  }

or

  methods: {
    setSubProp: call("myModule/nestedProperties@setSubproperty1")
  }

Actually I didn't found any example, is that possible?

@davestewart
Copy link
Owner

Hi there,

And thanks for the examples.

The call() helper is actually to call store actions.

What you want (I presume) is either the sync helper:

export default {
  computed: {
    value: sync('myModule/nestedProperties@subproperty1') // using sync, even though we won't get
  },
  methods: {
    setValue (value) {
      this.value = value
    }
  }
}

Or the global set method:

export default {
  methods: {
    setValue (value) {
      this.$store.set('myModule/nestedProperties@subproperty1', value)
    }
  }
}

Does that help?

@giuseppe-esposito-87
Copy link
Author

Whups, I forgot to reply 🤦

Yes, thank you, your answer solved my problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants