holy moly

pangratz prattles

Useful Ember.Observable Functions

I recently stumbled over some very handy functions in the Ember.Observable mixin, which is applied to Ember.Object’s. They are basically shortcuts for incrementing/decrementing a property and toggling a boolean.

incrementProperty and decrementProperty

1
2
3
4
5
6
7
8
9
10
11
var obj = Ember.Object.create({
  score: 10
});

obj.incrementProperty('score'); // score === 11
obj.incrementProperty('score', 5); // score === 16

obj.set('score', 10);

obj.decrementProperty('score'); // score === 9
obj.decrementProperty('score', 5); // score === 4

toggleProperty

1
2
3
4
5
6
var obj = Ember.Object.create({
  isVisible: true
});

obj.toggleProperty('isVisible'); // isVisible === false
obj.toggleProperty('isVisible'); // isVisible === true

Comments