Skip to content

Instantly share code, notes, and snippets.

@hoodwink73
Last active July 19, 2017 05:54
Show Gist options
  • Select an option

  • Save hoodwink73/6fc03de9b1b4be9dfbb13cba47484a31 to your computer and use it in GitHub Desktop.

Select an option

Save hoodwink73/6fc03de9b1b4be9dfbb13cba47484a31 to your computer and use it in GitHub Desktop.
Actions Up
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
launchConfirmDialog() {
this.set('confirmShown', true)
},
submitConfirm() {
this.get('onConfirm')(this.get('confirmValue'))
this.set('confirmShown', false)
},
cancelConfirm() {
this.set('confirmShown', false)
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
sendMessage(messageType, messageText) {
console.log('Message Sent', messageType, messageText)
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
userDidDeleteAccount() {
console.log('User Deleted')
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Playground to understand Ember Actions</h1>
<br>
<br>
{{user-profile}}
{{send-message}}
{{outlet}}
<br>
<br>
<button onclick={{action "launchConfirmDialog"}}>{{text}}</button>
{{#if confirmShown}}
{{yield confirmValue}}
<button onclick={{action "submitConfirm"}}>Okay</button>
<button onclick={{action "cancelConfirm"}}>Cancel</button>
{{/if}}
{{#button-with-confirmation
text="Click OK to send your message"
onConfirm=(action "sendMessage" "info")
as |confirmValue|
}}
{{input value=confirmValue}}
{{/button-with-confirmation}}
{{yield}}
{{button-with-confirmation
text="Click OK to delete your account."
onConfirm=(action "userDidDeleteAccount")
}}
{{yield}}
{
"version": "0.12.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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment