Why this matters
Simpler, well-named computed properties are easier to test, read, and adapt to changing requirements.
Complex computed properties should be split into as many simpler properties as possible.
Simpler, well-named computed properties are easier to test, read, and adapt to changing requirements.
Side-by-side examples engineers can pattern-match during review.
computed: {
price() {
const basePrice = this.manufactureCost / (1 - this.profitMargin)
return (
basePrice -
basePrice * (this.discountPercent || 0)
)
}
}computed: {
basePrice() {
return this.manufactureCost / (1 - this.profitMargin)
},
discount() {
return this.basePrice * (this.discountPercent || 0)
},
finalPrice() {
return this.basePrice - this.discount
}
}computed: {
complexValue() { /* multiple operations */ }
}computed: {
valuePart1() { /* operation 1 */ },
valuePart2() { /* operation 2 */ },
finalValue() { return this.valuePart1 + this.valuePart2; }
}From the same buckets as this rule.