Created
November 22, 2012 11:49
-
-
Save SweeD/4130748 to your computer and use it in GitHub Desktop.
EmberJS - Add a computed property via method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When i call get() for the property 'accountSettingsActive' i get a ComputedProperty object | |
App.ConcreteMenuView.create().get('accountSettingsActive'); | |
=> ComputedProperty | |
// But when i call get() for the initial defined property 'accountEmailActive' i get the right value back (false) | |
App.ConcreteMenuView.create().get('accountEmailActive'); | |
=> false | |
// What am i doing wrong? |
//is it this what you mean
Ember.computed.not = function(dependentKey) {
return Ember.computed(dependentKey, function(key) {
return !get(this, dependentKey);
});
};
Ok, plusgut from the irc-channel helped me.
The solution is:
// .....
addActiveCheckMethod: function(statePart){
functionName = statePart.replace('.', '_').camelize() + 'Active'; // the function name for 'account.settings' should be 'accountSettingsActive'
Em.defineProperty(this, functionName, function(){
return this.isActiveState(statePath);
}.property('App.router.currentState'))
},
// ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote the original Code in Coffee and ported it to js for this gist. (in case there is a lack of return calls or something... ^^ )