Skip to content

Instantly share code, notes, and snippets.

@pablobm
Last active November 30, 2015 16:41
Show Gist options
  • Save pablobm/7cceb249eb00a3b274aa to your computer and use it in GitHub Desktop.
Save pablobm/7cceb249eb00a3b274aa to your computer and use it in GitHub Desktop.
Mixin event handler is shadowed
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
import Ember from 'ember';
import MyMixin from 'demo-app/my-mixin';
export default Ember.Route.extend(MyMixin, {
actions: {
myEvent() {
console.log('handled by route');
return true;
}
},
});
<h1>Welcome to {{appName}}</h1>
<br>
<button {{action 'myEvent'}}>send <code>myEvent</code></button>
<p>On clicking the above button, I'd like the console to print the following (in either order):</p>
<pre>
handled by mixin
handled by route
</pre>
<p>However, only the first message appears. This is because the action handler at ApplicationRoute is shadowed by the one in MyMixin.</p>
<p>In my application, the event I'm trying to handle is 'willTransition'. This problem creates a situation where I cannot have a Mixin with a common handling case for this event, and use it on a route that has its own handling of this, where both should apply.</p>
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';
export default Ember.Mixin.create({
actions: {
myEvent() {
console.log('handled by mixin');
return true;
}
},
});
{
"version": "0.4.16",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment