Closed knownasilya closed 9 years ago
Great idea. I assume that just uses the key
argument to the computed property function, right?
Actually, not sure how to do this - revoke
is a method, not a computed property, so it wouldn't have access to the key
.
Maybe look at how Ember.inject.service()
works?
https://github.com/emberjs/ember.js/blob/v1.11.1/packages/ember-metal/lib/injected_property.js#L26
It seems like Ember.inject.*
methods return an InjectedProperty
, which is essentially a computed property whose getter looks something up on the container and returns that. For instance, if you say
var book = Ember.Object.extend({
session: Ember.inject.service()
});
You can only access the session
service via book.get('session')
. book.session
will return the InjectedProperty
instance.
Our problem is that revoke
is a function. Even if we register the function with the container (and use instantiate: false
) so it could be looked up, we only get the function back if we use user.get('revoke')
, meaning it can only be invoked via user.get('revoke')({ some: 'params' })
.
The double parens isn't very elegant syntax, and you'll lose the calling context (i.e. this
won't be user
).
I'm not sure this kind of dynamic lookup is possible with a function value, unless I'm missing something.
You are probably right. Oh well :smile_cat:
Example
Instead of duplication, e.g.
revoke: action('revoke')
.