emberjs/ember.js — pull request #9477 by TrueNorth (2014-11-03 07:51:19+00:00)
Title: [FEATURE computed-property-syntax-new]

RFC: https://github.com/emberjs/rfcs/pull/11

This feature adds some optional new syntax for defining computed properties. Current methods for building computed properties still work fine, but now we can pass an object instead of a function

```
a: Ember.computed('b', 'c', {
get: function () { ... },
set: function (key, val, oldVal) { ... }
});
```

So, here's a concrete example of a "writable" macro with the current syntax
```js
var Person = Ember.Object.extend({
fullName: Ember.computed('firstName', 'lastName', function (key, val, oldVal) {
if (arguments.length === 1) {
//getter
return this.get('firstName') + ' ' + this.get('lastName');
}
else {
//setter
var nameComponents = val.split(' ');
this.setProperties({
firstName: nameComponents[0],
lastName: nameComponents[1]
});
return val;
}
})
});
```
And the equivalent with the proposed syntax.
```js
var Person = Ember.Object.extend({
fullName: Ember.computed('firstName', 'lastName', {
get: function () { // Getter
return this.get('firstName') + ' ' + this.get('lastName');
},
set: function (key, val, oldVal) { // Setter
var nameComponents = val.split(' ');
this.setProperties({
firstName: nameComponents[0],
lastName: nameComponents[1]
});
return val;
}
})
});
```