Skip to content

Instantly share code, notes, and snippets.

@greyhwndz
Forked from KTKate/actions-yo.component.js
Last active August 31, 2015 04:47
Show Gist options
  • Save greyhwndz/32e63007da6906270f70 to your computer and use it in GitHub Desktop.
Save greyhwndz/32e63007da6906270f70 to your computer and use it in GitHub Desktop.
Component - Closure Actions
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
doIt(msg){
this.sendAction('theAction', msg);
}
}
});
<button {{action (action attrs.clicked)}}>Click Me</button>
<br />
<br />
<button {{action (action attrs.pressed)}}>Press Me</button>
<br />
<br />
<button {{action 'doIt' 'messagePassed'}}>Do It!</button>
import Ember from 'ember';
let counter = 1;
let incrementer = 1;
export default Ember.Controller.extend({
someFlag: 'no',
something: 'none',
actions: {
controllerAction(){
this.set('someFlag', counter++ + ' clicks');
},
controlleryAction(){
this.set('something', incrementer++ + ' presses');
},
justDoIt(msg){
alert('Doing It: ' + msg);
}
}
});
Clicks? <strong>{{someFlag}}</strong>
<br />
Presses? <strong>{{something}}</strong>
<br />
<br />
{{actions-yo clicked=(action 'controllerAction') pressed=(action 'controlleryAction') theAction='justDoIt'}}
{
"version": "0.4.9",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment