emberjs/ember.js — Issue #552: [suggestion] provide observed/dependent properties as function args
Author: algesten
Created: 2012-02-29 05:03:34+00:00
State: open

I found myself having a computed property that relies on an ever growing set of other properties and there's a fair amount of code duplication of each property path.

Current situation:

...
typeText: function () {
return !(this.get('typeDate') || this.get('typeSuggest') || this.get('typeCheckbox')
|| this.get('typeInfo') || this.get('typeSelect'));
}.property('typeDate', 'typeSuggest', 'typeCheckbox', 'typeInfo', 'typeSelect').cacheable()
...

The verbosity would be worse if I have had deep paths such as `App.model.myProp`.

Since the order is known, it would be neat if the dependent/observed properties could be provided as function arguments. Consider the following.

...
typeText: function (a1, a2, a3, a4, a5) {
return !(a1 || a2 || a3 || a4 || a5);
}.property('typeDate', 'typeSuggest', 'typeCheckbox', 'typeInfo', 'typeSelect').asArgs()
...

or even using `arguments[]`.

...
typeText: function () {
var a = arguments;
return !(a[0] || a[1] || a[2] || a[3] || a[4]);
}.property('typeDate', 'typeSuggest', 'typeCheckbox', 'typeInfo', 'typeSelect').asArgs()
...

I could see a potential problem that the function may not need all arguments, in which case there may have been unnecessary properties evaluated. Hence the use for an `asArgs()` to enable this functionality rather than having it as on by default.

Observed properties could work the same way.

Thoughts?