mesqueeb / vuex-easy-access

Unified syntax for accessing your Vuex store through simple set() and get() functions + auto generate mutations
https://mesqueeb.github.io/vuex-easy-access/
MIT License
52 stars 6 forks source link

"module/set" to mutate the whole state #37

Closed joshua1 closed 5 years ago

joshua1 commented 5 years ago

Can we have an additional feature where we call store.set('module/',payload) or dispatch('set/moduleName/',payload) to mutate the state object as a whole as opposed to mutating property after property. the internal implementation can just Object.assign the payload to the state. doing itemized set on an object can be a pain or take a lot more lines of code to write each time.key will be the / with no property name after . i will see about a PR , but might be quicker from your end

joshua1 commented 5 years ago

currently using a helper method like this . testing to see how efficient it is

const setState = async (moduleName, payload) => {
  Object.keys(payload).forEach(key => {
    store.dispatch(`${moduleName}/set/${key}`, payload[key])
  })
}
mesqueeb commented 5 years ago

Hi. @joshua1 Sorry I came back so late on this.

But this is not good practice. You should never do this to keep readability in your code. I would always recommend against this. 🙃

joshua1 commented 5 years ago

Not about readability and not a bug that needs fixing . More so , saying its not good practice is wrong. has nothing to do with readability.It's simply asking of a way to do object update that the library doesn't currently have.

mesqueeb commented 5 years ago

I'm sorry. 😣 I didn't mean to upset you in any way.

I don't want to offer this as a feature but, I believe your wrapper function that you wrote should be good enough. If I had to implement it myself it would be a similar implementation. 😉

Sorry again and I hope you understand.

Sent with GitHawk