Created
June 20, 2015 04:54
-
-
Save mde/ae752b3bb4a66c152371 to your computer and use it in GitHub Desktop.
PropagateAction mixin
This file contains hidden or 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
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); | |
} | |
}); |
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
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.