Skip to content

Instantly share code, notes, and snippets.

@amk221
Last active July 16, 2020 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amk221/aaaef30bd40289a29f4567229548cd7b to your computer and use it in GitHub Desktop.
Save amk221/aaaef30bd40289a29f4567229548cd7b to your computer and use it in GitHub Desktop.
ED destroy
// import RESTAdapter from '@ember-data/adapter/rest';
import RESTAdapter from 'ember-data/adapters/rest';
export default class FooAdapter extends RESTAdapter {
ajax(path, method, options) {
return {
foos: [{
id: 1,
name: 'Foo 1'
}, {
id: 2,
name: 'Foo 2'
}]
}
}
}
import Controller from '@ember/controller';
import { action } from '@ember/object';
export default class ApplicationController extends Controller {
@action
deleteFoo(foo) {
foo.destroyRecord().then(() => this.refreshRoute());
}
}
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default class extends Model {
@attr() name;
}
import Route from '@ember/routing/route';
import { inject } from '@ember/service';
export default class ApplicationRoute extends Route {
model() {
console.log('model: finding foos');
return this.store.query('foo', {
q: 'my search'
});
}
setupController(controller, model) {
console.log('setupController: found', model.length, 'foos');
super.setupController(...arguments);
controller.refreshRoute = this.refresh.bind(this);
}
}
<ul>
<li>
Using ED 3.10, click delete.<br>
Notice the record is removed from the UI.
</li>
<li>
Using ED 3.18, try again.<br>
Notice now that the record is not removed from the UI.
</li>
</ul>
<br><br>
{{#each @model as |foo|}}
{{foo.id}} - {{foo.name}}
<button {{on "click" (fn this.deleteFoo foo)}}>Delete</button>
<br>
{{/each}}
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0",
"ember-data": "3.10.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment