Reputation: 419
I've been having a look at https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/computed.js#L482 and I've seen that computed properties are actually way more powerful that they're documented on the guides.
Some really useful straightforward uses cases are:
Ember.Object.create({
propertyA: Ember.computed.empty('anotherProperty'),
propertyB: Ember.computed.not('anotherProperty'),
propertyB: Ember.computed.equal('anotherProperty', "Ed Balls")
});
But I don't really get how the more advanced cases work: https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/computed.js#L617
I could really use some clarification - I suspect I might be writing an aweful lot of boilerplate that I could avoid with a proper use of those :smiley:.
Once I get how they work, I could definitely try to add some documentation to the guides.
Upvotes: 1
Views: 2495
Reputation: 23322
Some use cases (although not that advanced only trivial) could look like:
...
// this could be in your controller
hasPost: Ember.computed.bool('content.post')
hasComments: Ember.computed.bool('content.post.comments')
showComments: Ember.computed.and('hasPost', 'hasComments')
// here you could perfectly bind on the showComments property
...
One thing you should tough take into account is that CP are not chain-able (for now), so maybe this limits it's most advanced cases of use. But if they where chain-able then you could do something like:
...
// not possible at the moment
showComments: Ember.computed.bool('content.post') && Ember.computed.bool('content.post.comments')
...
Some use cases (although only test cases) can be found here. This issue is maybe also of interest.
Hope it helps
Upvotes: 1