Ember.ComputedProperty Class packages/ember-metal/lib/computed.js:101
meta
(meta)
In some cases, you may want to annotate computed properties with additional metadata about how they function or what values they operate on. For example, computed property functions may close over variables that are then no longer available for introspection.
You can pass a hash of these values to a computed property like this:
1 2 3 4 |
person: function() { var personId = this.get('personId'); return App.Person.create({ id: personId }); }.property().meta({ type: App.Person }) |
The hash that you pass to the meta() function will be saved on the
computed property descriptor under the _meta key. Ember runtime
exposes a public API for retrieving these values from classes,
via the metaForProperty() function.
Parameters:
- meta Hash
property
(path)
Ember.ComputedProperty
Sets the dependent keys on this computed property. Pass any number of arguments containing key paths that this computed property depends on.
1 2 3 4 5 6 7 8 |
MyApp.president = Ember.Object.create({
fullName: Ember.computed(function() {
return this.get('firstName') + ' ' + this.get('lastName');
// Tell Ember that this computed property depends on firstName
// and lastName
}).property('firstName', 'lastName')
});
|
Parameters:
- path String
- zero or more property paths
Returns:
readOnly
Ember.ComputedProperty
Call on a computed property to set it into read-only mode. When in this mode the computed property will throw an error when set.
1 2 3 4 5 6 7 |
MyApp.person = Ember.Object.create({
guid: function() {
return 'guid-guid-guid';
}.property().readOnly()
});
MyApp.person.set('guid', 'new-guid'); // will throw an exception
|
Returns:
volatile
Ember.ComputedProperty
Call on a computed property to set it into non-cached mode. When in this mode the computed property will not automatically cache the return value.
1 2 3 4 5 |
MyApp.outsideService = Ember.Object.create({
value: function() {
return OutsideService.getValue();
}.property().volatile()
});
|
Fork Us!