emberjs/ember.js — Issue #386: Automatic dependency recognition
Author: sheerun
Created: 2012-01-12 15:20:09+00:00
State: open

How about automatic recognizing (on first run) in `Ember.computed` body function what dependencies it uses?

See the example from docs:

``` javascript
Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,

fullName: Ember.computed(function() {
var firstName = this.get('firstName');
var lastName = this.get('lastName');

return firstName + ' ' + lastName;
}).property('firstName', 'lastName')
});
```

My idea is to reprogram `this.get` method so they'd automatically add `property` dependencies if executed in context of `Ember.computed`, so above code would become shorter and more coffee-script friendly:

``` javascript
Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,

fullName: Ember.computed(function() {
var firstName = this.get('firstName');
var lastName = this.get('lastName');

return firstName + ' ' + lastName;
})
});
```

``` coffeescript
Person = Ember.Object.extend
firstName: null
lastName: null
fullName: Ember.computed ->
@get("firstName") + " " + @get("lastName")
```

Oh. And use of `property()` method on `Ember.computed` would disable this behavior so code would be backward-compatible and customizable if needed to.

What do you think?