Ember.js abbreviation for a generic computed property model

In Ember.js, I find myself defining computed properties that look like this:

someProp: function(){ return this.get('otherProp'); }.property('otherProp') 

or

 someProp: function(){ return this.get('otherObject.prop'); }.property('otherObject.prop') 

Is there a shorter way to write computed properties following these patterns?

+7
source share
1 answer

With a little research, you can drain it a bit by doing the following with Ember.computed.alias :

 someProp: Ember.computed.alias("otherObject.prop") 

You can also use alias to set this property. Given an Ember object that implements the above property, you can do:

 obj.set("someProp", "foo or whatever"); // The set will be propagated to otherObject.prop 

Link to Ember source for Ember.computed.alias


Update: Ember.computed.oneWay

Recently, a new abbreviated expression ( oneWay ) has been added to Ember, which is also possible for this requirement. The difference is that the abbreviation oneWay only works if received . Therefore, this haircut is faster when creating an object than the more complex alias .

 someProp: Ember.computed.oneWay("otherObject.prop") 

Link to Ember source for Ember.computed.oneWay

+12
source

All Articles