Skip to content

Instantly share code, notes, and snippets.

@LevelbossMike
Created January 12, 2016 09:38
Show Gist options
  • Save LevelbossMike/d7f47182a1c746b0b4c4 to your computer and use it in GitHub Desktop.
Save LevelbossMike/d7f47182a1c746b0b4c4 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
const COLORS = [
{ name: "red"},
{ name: "green"},
{ name: "refactor"}
].map((c) => Ember.Object.create(c));
export default Ember.Controller.extend({
appName:'Ember Twiddle',
colors: COLORS,
actions: {
deleteColor(color) {
const colors = this.get('colors');
colors.removeObject(color);
},
reset() {
const COLORS = [
{ name: "red"},
{ name: "green"},
{ name: "refactor"}
].map((c) => Ember.Object.create(c));
this.set('colors', COLORS);
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<ul>
{{#each colors as |color|}}
{{color-entry color=color deleteEntry=(action 'deleteColor')}}
{{/each}}
<button {{action 'reset'}}>Reset</button>
</ul>
<br>
<br>
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
sayName() {
alert(this.get('color.name'));
},
delete() {
this.attrs.deleteEntry(this.get('color'));
}
}
});
<li{{action 'sayName'}}>{{color.name}}<span><button {{action 'delete'}}>X</button></span></li>
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment