lines: Ember.computed('linesReady', 'selectedID', function () {
let selectedID= this.get('selectedID')
let lines= this.get('linesReady')
return lines.map(line => {
if (line.options.entityID === selectedID) {
Ember.set(line, 'isSelected', true)
} else {
Ember.set(line, 'isSelected', false)
}
if (!line.special) {
line.options.weight = lienWeight
}
return line
})
})
As you can see, I have to use Ember.set in order to avoid ‘You must use Ember.set blah blah’
If I use Ember.set I get 'Do not send events or actions in Computed Properties. This will cause data flow issues in the application, where the accessing… ’
Computed properties should not have side effects. They should be pure functions. That is indeed a best practice.
How do I explain this? When someone calls .get(‘xxx’) they would not expect another property ‘yyy’ to change. Furthermore, the function inside the computed property does not get called every time someone calls get, but only if one of the dependent properties has changed since it was last called. This makes it really hard to know in practice whether ‘yyy’ will be changed when you call .get(‘xxx’) and that makes for really hard to find bugs.
Very often when someone asks so how do I do x when we say x is a bad practice, they are really trying to implement y and think x is the best way. So what are you trying to do?