3
votes

Now, this is really a question that's evolved from this. There is a whole lot more info there, but I guess, it's better to ask a direct specific question. So here it goes:

We typically define actions in a controller like so:

var FooController = Ember.Controller.extend({
    actions: {
        login: function() {
        }
    }
});

Is there a way to define a catch all action handler, like so (hypothetically):

actions: {
    login: function() {
    },
    *: function(actionName, paramArray) {
    }
}

This would be analogous to embers catch all route which I believe has been implemented, though I haven't tried it.

I need this because my Ember.Component renders a user supplied partial template using the {{partial}} helper. This partial might have {{action}}'s specified in them. These actions don't bubble up to the calling controller or route and are lost inside the component. This fact is mentioned in the docs in para 4.

If a catch all action was possible, my component could implement it and send the action back to the caller using something like this:

actions: {
    *: function(actionName, paramArray) {
        this.sendAction(actionName, paramArray)
    }
}
1

1 Answers

2
votes

The functionality around the actions hash on controllers, views and routes is provided by the action handler mixin [1]. As you can see, it injects the send(actionName) method and makes enables an object to receive actions. You can now easily override this function and catch all actions instead of looking for it in the actions hash -- which is what the implementation does.

[1] https://github.com/emberjs/ember.js/blob/v1.3.0/packages/ember-runtime/lib/mixins/action_handler.js#L8