Skip to content

Instantly share code, notes, and snippets.

@leodutra
Last active June 9, 2019 09:09
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leodutra/0cfd71fb13e77fa674cc0ceb18477751 to your computer and use it in GitHub Desktop.
Save leodutra/0cfd71fb13e77fa674cc0ceb18477751 to your computer and use it in GitHub Desktop.
Function for mapping Vuex states two way
import { mapState } from 'vuex'
export default function mapStatesTwoWay (namespace, states, updateCb) {
const mappedStates = mapState(namespace, states)
const res = {}
for (const key in mappedStates) {
res[key] = {
set (value) {
updateCb.call(this, { [key]: value })
},
get () {
return mappedStates[key].call(this)
}
}
}
return res
}
@leodutra
Copy link
Author

Sorry for the delay... I'll create a module and a demo as soon as possible... please remind me it it takes too long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment