Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created May 1, 2019 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uno-de-piera/b9fea2b7d2eafb3a6c42ad9d01f8dcfa to your computer and use it in GitHub Desktop.
Save uno-de-piera/b9fea2b7d2eafb3a6c42ad9d01f8dcfa to your computer and use it in GitHub Desktop.
import store from './store';
export function computedPropertiesGenerator (props = [], {pathStore, mutation} = {}) {
return props.reduce((obj, prop) => {
obj[prop.property] = {
get() {
return store.state[pathStore][prop.property] || prop.defaultValue;
},
set(value) {
store.commit(mutation, {
property: prop.property,
value
})
}
}
return obj
}, {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment