-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathdestroy.js
32 lines (25 loc) · 998 Bytes
/
destroy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import { deleteRecord } from '@ember-data/json-api/request';
export default Route.extend({
store: service(),
async model() {
performance.mark('start-data-generation');
const payload = await fetch('./fixtures/destroy.json').then((r) => r.json());
performance.mark('start-push-payload');
const { store } = this;
const parent = store.push(payload);
performance.mark('start-destroy-records');
const children = await parent.children;
const childrenPromise = Promise.all(
children.slice().map((child) => {
child.deleteRecord();
return store.request(deleteRecord(child)).then(() => child.unloadRecord());
})
);
parent.deleteRecord();
const parentPromise = store.request(deleteRecord(parent)).then(() => parent.unloadRecord());
await Promise.all([childrenPromise, parentPromise]);
performance.mark('end-destroy-records');
},
});