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); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is why we write test! Nice job. :) Let's attack this tomorrow.