davestewart / vuex-pathify

Vue / Vuex plugin providing a unified path syntax to Vuex stores
https://davestewart.github.io/vuex-pathify
MIT License
1.37k stars 57 forks source link

[Feature Request] Allow Pathify-style commits in actions #79

Open davestewart opened 5 years ago

davestewart commented 5 years ago

This post is asking whether you can do Pathify style commits in actions, and the answer is currently no:

However, a quick monkey patch proves it might be possible to intercept the native commits and do something with them:

var commit = store.commit
store.commit = function (...args) {
  console.log('COMMITTING', ...args)
  commit(...args)
}
COMMITTING locateList/id 51ff8a16-9f2b-41da-93cf-a07945a46318 undefined

So with that in mind, it might be possible to detect @ characters and do a Pathify style set() instead.

Another option would be wrapping this in the existing commit helper, or even adding a helper to build and pass Payloads, like this demo

davestewart commented 5 years ago

OK, PoC working for root and modules here:

Tasks:

bkarlson commented 5 years ago

would be great to have this released, as I was going in circles in google trying to keep my code simple yet my state nested. Seems like with Vuex you cannot have both. Pathify to the rescue!

davestewart commented 5 years ago

Hey @bkarlson - it's not a priority for me now (I have other things I want to spend my ODD dev time on) so don't hold your breath!

DarkLite1 commented 4 years ago

Yeah, I also ended up here thinking that this would've been a really cool addition to the library. Shame you're no longer into Vuex anymore if I read it correctly. Classes are indeed easier for OO devs but I'm more of a functional programming type of person. Anyway, thanks again for this amazing library. It already saved me a lot of time and effort in writing pointless setters.

Maybe I'll just use your previous suggestion in another post:

import store from '../index'
const actions = {
    foo({commit}, value) {
        store.set('page@status', value)
    }
}