Skip to content

Instantly share code, notes, and snippets.

@mde
Created June 20, 2015 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mde/ae752b3bb4a66c152371 to your computer and use it in GitHub Desktop.
Save mde/ae752b3bb4a66c152371 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link
Author

mde 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