Skip to content

Instantly share code, notes, and snippets.

@gdgupta11
Last active December 12, 2018 02:54
Show Gist options
  • Save gdgupta11/8230324db811e5e295e6343bfa792f82 to your computer and use it in GitHub Desktop.
Save gdgupta11/8230324db811e5e295e6343bfa792f82 to your computer and use it in GitHub Desktop.
Basics_action_bubbling
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
hasHat: true,
hatColor: "blue",
colors: ["blue", "red","green", "yellow", "black", "purple", "orange"],
actions: {
putOnHat(color){
this.set('hatColor', color);
this.set('hasHat', true);
},
takeOffHat(){
this.set('hasHat', false);
return true;
},
pressRelease(){
alert("This action is taking place in controller");
// while mentioning return as true it bubbles the action for next execution as well.
// otherwise if there are multiple same actions defined in different places, only first will execute
return true;
}
}
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
pressRelease(){
alert("This is press release and action is taking in application.js");
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<h2> Hat.io </h2>
{{#if hasHat }}
<h3> You are wearing a<span style="color:{{hatColor}};"> {{hatColor}} </span> hat </h3>
<button {{action 'takeOffHat' }}> Take off the Had </button>
{{else}}
<p> You don't have any hat :( </p>
<p> Put on a hat </p>
{{#each colors as |color| }}
<button {{action 'putOnHat' color }} style="color:{{color}};" > {{color}} </button>
{{/each}}
{{/if}}
<button {{action 'pressRelease' }}> Press Release </button>
{{outlet}}
<br>
<br>
{
"version": "0.13.1",
"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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment