Helper for use props of Redux with Vue.js using Vuex and Vuedeux
When change only one prop from redux state then triggering all computed and wathers where using props of redux state, which did not change, because always change root object. It's sensitive when prop is object or array.
- Created computed props from selectors with prefix(default: "inner_");
- Created initial values from props using selectors;
- Created watchers for "inner_" props and when object mutated from selectors then set prop this value.
import { mapState } from "vuex";
import prepareProps from "vue-redux-prepare-props";
const props = {
prop1: state => state.redux.prop1,
...
propN: state => state.redux.propN
};
const {calcs, datas, watchers} = prepareProps(props);
export default {
computed: {
//redux store
...mapState(calcs),
...
},
watch: {
...watchers,
...
},
data () {
return {
...datas(this),
...
};
},
...
};