ChrisVilches/Beautiful-Bridges

(Possible code smell) Update methods in model do not trigger 'change' events

Closed this issue · 1 comments

https://github.com/ChrisVilches/Beautiful-Bridges/blob/main/src/models/InputData.js

These methods should also trigger the vanilla change event, along with the change:ground:length for the ones that modify the array length.

The reason is simply that it might become confusing as to why it's not triggering the change event when it seems like it should do so.

addGround: function () {
  this.get('ground').push({
    x: '',
    y: ''
  })
  this.trigger('change:ground:length')
},
removeGround: function (i) {
  this.get('ground').splice(i, 1)
  this.trigger('change:ground:length')
},
updateGround: function (i, type, value) {
  this.get('ground')[i][type] = value
},

In case of fixing this, note that it's better to execute the built-in set method, which triggers the event automatically, passing some other useful data related to the event (don't trigger the event manually because it will lack that information).

Fixed here: c19f641