If you have an observer like this:
1 2 3 4 |
observeNames: Ember.observer('firstName', 'lastName', function() { var fullName = `${this.get('firstName')} ${this.get('lastName')}'; this.set('fullName', fullName); }) |
Then in your code, you write:
1 2 |
this.set('firstName', 'Bart'); this.set('lastName', 'Simpson'); |
Your fullName observer will fire twice because both dependent properties changed. You can work around this by using Ember.run.once:
1 2 3 4 5 6 |
observeNames: Ember.observer('firstName', 'lastName', function() { Ember.run.once(() => { var fullName = `${this.get('firstName')} ${this.get('lastName')}'; this.set('fullName', fullName); }); }) |
This will ensure that any processing you need to do only happens once, and happens in the next run loop once all bindings are synchronized.