Skip to content

Instantly share code, notes, and snippets.

@nickiaconis
Last active June 24, 2016 21:18
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 nickiaconis/9c07d31a1823b970f5991192e4970d71 to your computer and use it in GitHub Desktop.
Save nickiaconis/9c07d31a1823b970f5991192e4970d71 to your computer and use it in GitHub Desktop.
Actions Bubble Up Routes
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
name: function() {
return this.toString();
}.property()
});
import Ember from 'ember';
export default Ember.Controller.extend({
name: function() {
return this.toString();
}.property()
});
import Ember from 'ember';
export default Ember.Controller.extend({
name: function() {
return this.toString();
}.property()
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('parent', function() {
this.route('child');
});
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
bubblyAction(controller) {
window.alert('The action bubbled to "' + this.toString() + '" from "' + controller + '"!');
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
});
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
bubblyAction(controller) {
window.alert(this.toString() + ' has handled the action sent by ' + controller + '!');
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{link-to "Application" "index"}}
<br>
{{link-to "Parent Route" "parent"}}
<br>
{{link-to "Child Route" "parent.child"}}
<button {{action "bubblyAction" name}}>click me from the index route!</button>
<button {{action "bubblyAction" name}}>click me from the child route!</button>
<button {{action "bubblyAction" name}}>click me from the parent route!</button>
{
"version": "0.9.3",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment