Skip to content

Instantly share code, notes, and snippets.

@mrVanboy
Last active April 24, 2017 12:32
Show Gist options
  • Save mrVanboy/6a4ac34aa0641a7a6641d425921f64c8 to your computer and use it in GitHub Desktop.
Save mrVanboy/6a4ac34aa0641a7a6641d425921f64c8 to your computer and use it in GitHub Desktop.
test destroying
import Ember from 'ember';
let Prvek = Ember.Object.extend({
title: "I am prverk",
init(){
let pole = this.constructor.pole;
this.set('id',pole.length > 0 ? pole[pole.length-1].id + 1 : 0);
this.constructor.pole.pushObject(this);
},
willDestroy(){
//this.constructor.runDeleteCallback(this);
// console.log(`Destroing element with id ${this.get('id')}`);
let pole = this.constructor.pole;
let index = pole.indexOf(this);
pole.splice(index,1);
}
});
// statická metoda jednotná pro celou třidu a všechny instance
Prvek.reopenClass({
pole: []
});
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
pole: Prvek.pole,
init(){
this._super(...arguments);
Prvek.create();
Prvek.create();
Prvek.create();
/*
Prvek.deleteCallback((item)=>{
let pole = this.get('pole');
let index = pole.indexOf(item);
pole.splice(index,1);
this.notifyPropertyChange('pole');
});
*/
},
actions: {
delete(item){
item.destroy();
this.notifyPropertyChange('pole');
// console.log('Pole prvku:', this.get('pole'));
},
add(){
Prvek.create();
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<p>
Velikost pole: {{pole.length}}
<button {{action "add"}}>Increase</button>
</p>
<ul>
{{#each pole as |prvek|}}
{{#unless prvek.isDestroying}}
<li>Hello, {{prvek.id}}!<button {{action "delete" prvek}}>Delete</button> isDestroyed:{{prvek.isDestroyed}}</li>
{{/unless}}
{{/each}}
</ul>
{
"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