Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PropagateAction mixin
import Ember from 'ember';
export default Ember.Mixin.create({
_sendActionPropagateChannel: '_sendActionPropagateChannel',
actions: {
_sendActionPropagateChannel: function () {
try {
this.send.apply(this, arguments);
}
catch (err) {
if (err instanceof Ember.Error) {
throw err;
}
try {
this.sendActionPropagate.apply(this, arguments);
}
catch (err) {
if (err instanceof Ember.Error &&
err.message.indexOf('_sendActionPropagateChannel') > -1) {
throw new Error('Problem using `sendActionPropagate`. ' +
'You need to use PropagateAction mixin at every level of the ' +
'Component hierarchy up to an including the Controller');
}
throw err;
}
}
}
},
sendActionPropagate: function () {
var args = Array.prototype.slice.call(arguments);
args.unshift('_sendActionPropagateChannel');
this.sendAction.apply(this, args);
}
});
@andrew-zenefits

This comment has been minimized.

Copy link

commented Jun 25, 2015

If any level is missing this mixin line 32 will fail in an uncontrolled and confusing manner (<console-app@component:list-items::ember4035> had no action handler for: _sendActionPropagateChannel).

However if I put a try-catch around line 32 it swallows up every other type of error and isn't helpful in other failure situations. I'll give this a look again tomorrow.

@mde

This comment has been minimized.

Copy link
Owner Author

commented Jun 25, 2015

This is why we write test! Nice job. :) Let's attack this tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.