Skip to content

Instantly share code, notes, and snippets.

@jmimi
Created March 1, 2017 20:21
Show Gist options
  • Save jmimi/09083b26ea467379466b475ddc2d2c31 to your computer and use it in GitHub Desktop.
Save jmimi/09083b26ea467379466b475ddc2d2c31 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
const Binder = Ember.Object.extend({
id: Ember.computed(function() {
return Ember.guidFor(this);
}),
value: null,
//just for show and css manipulating in liquid-fire
removing: false,
binder: Ember.computed('removing', function(){
return `${this.get('id')}-${this.get('removing')}`;
})
});
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
rawData: [{id: 1, name: 'Test 1'}, {id: 2, name: 'Test 2'}, {id: 3, name: 'Test 3'}, {id: 4, name: 'Test 4'}],
list: Ember.computed('rawData.[]', function(){
return this.get('rawData').map(function(item){
return Binder.create({
value: item
});
});
}),
actions: {
removeItem(item){
Ember.set(item, 'removing', true);
Ember.run.later(this, function() {
this.get('rawData').removeObject(item.value);
}, 1000);
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
{{#each list as |item|}}
<div>
{{#liquid-bind item.binder class="data-binder" as |currentModel|}}
<span>id : {{item.value.id}}</span>
<span>name : {{item.value.name}}</span>
<button {{action "removeItem" item}}>Remove</button>
{{/liquid-bind}}
</div>
{{/each}}
<br>
export default function() {
this.transition(
this.matchSelector('.data-binder'),
this.toValue(function(value){
return value.indexOf('true') > 0;
}),
this.use('fade', {duration: 1000})
);
};
{
"version": "0.11.0",
"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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {
"liquid-fire": "0.27.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment