Skip to content

Instantly share code, notes, and snippets.

@lmammino
Created August 9, 2019 08:50
Show Gist options
  • Save lmammino/3ed9114e1c95319f4ba1372c91aff21a to your computer and use it in GitHub Desktop.
Save lmammino/3ed9114e1c95319f4ba1372c91aff21a to your computer and use it in GitHub Desktop.
Exposing configurable functions to components
import Ember from 'ember';
export default Ember.Component.extend({
onPrimaryClick: null,
onSecondaryClick: null,
actions: {
triggerPrimaryClick() {
if (this.onPrimaryClick) {
this.onPrimaryClick();
}
},
triggerSecondaryClick() {
if (this.onSecondaryClick) {
this.onSecondaryClick();
}
}
},
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
showAlert() {
alert('hello');
},
consoleLog() {
console.log('hello');
},
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{clickable-buttons
onPrimaryClick=(action 'showAlert')
onSecondaryClick=(action 'consoleLog')
}}
<button {{action "triggerPrimaryClick"}}>primary action</button>
<button {{action "triggerSecondaryClick"}}>secondary action</button>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment