Reputation: 31
How to keep the clean/maintainable while only the getters and actions are different?
Do I use mixin? Higher order component? Use switch cases?
And explain you choice if possible
For instance, the following components are:
sameFunction1()
and sameFunction2()
export default {
// ...
computed: {
...mapGetters([
'getDog1',
'getCat1',
])
},
methods: {
...mapActions([
'setDog1',
'setCat1',
])
sameFunction1() {...},
sameFunction2() {...},
},
}
export default {
// ...
computed: {
...mapGetters([
'getDog2',
'getCat2',
])
},
methods: {
...mapActions([
'setDog2',
'setCat2',
]),
sameFunction1() {...},
sameFunction2() {...},
},
}
Upvotes: 2
Views: 61
Reputation: 31
Based on Estus Flask comment
// define a mixin object
var myMixin = {
methods: {
sameFunction1() {...},
sameFunction2() {...},
}
}
export default {
mixins: [myMixin],
// ...
computed: {
...mapGetters([
'getDog1',
'getCat1',
])
},
methods: {
...mapActions([
'setDog1',
'setCat1',
])
},
}
export default {
mixins: [myMixin],
// ...
computed: {
...mapGetters([
'getDog2',
'getCat2',
])
},
methods: {
...mapActions([
'setDog2',
'setCat2',
]),
sameFunction1() {...},
sameFunction2() {...},
},
}
Upvotes: 1