Skip to content

Instantly share code, notes, and snippets.

@rwjblue
Forked from amk221/components.my-component.js
Created September 13, 2016 21:37
Show Gist options
  • Save rwjblue/215fa5d37088e9fdc6f0415b1f38e6de to your computer and use it in GitHub Desktop.
Save rwjblue/215fa5d37088e9fdc6f0415b1f38e6de to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Controller.extend({
init() {
this._super(...arguments);
this.set('things', [
'qux',
'foo',
'baz',
'bar'
]);
},
sortedThings: Ember.computed('things.[]', function() {
return this.get('things').sort();
}),
actions: {
removeThing(thing) {
console.log('removeThing', thing);
this.get('things').removeObject(thing);
},
toggleEditMode() {
this.toggleProperty('editMode');
}
}
});
{{#my-component things=sortedThings as |thing|}}
{{thing}}
{{#if editMode}}
<button onclick={{action 'removeThing' thing}}>
Remove {{thing}}
</button>
{{/if}}
<br>
{{/my-component}}
< hr/>
{{#each sortedThings as |thing|}}
{{thing}}
{{#if editMode}}
<button onclick={{action 'removeThing' thing}}>
Remove {{thing}}
</button>
{{/if}}
<br>
{{/each}}
<br>
<button onclick={{action 'toggleEditMode'}}>
Toggle edit mode
</button>
{{#each things as |thing|}}
{{yield thing}}
{{/each}}
{
"version": "0.10.5",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "canary",
"ember-data": "2.8.0",
"ember-template-compiler": "canary",
"ember-testing": "canary"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment