Example of simple mapGetter system
by darkylmnx
HTML
<pre></pre>
Babel + JSX
const computed = {
...mapGetters(['getterA', 'getterB', 'last']),
hi() {
console.log('im just a computed');
}
};
// print
console.log(computed);
const pre = document.querySelector('pre');
pre.textContent = printobj(computed);
// end print
function mapGetters(getterNames) {
const myComputed = {};
getterNames.forEach(getterName => {
myComputed[getterName] = function() {
return this.$store.getters[getterName]
};
});
return myComputed;
}
////////
function printobj(obj) {
return JSON.stringify(obj, (k, v) => {
return (typeof v === 'function') ? '' + v : v;
}, ' ');
}