Last active
April 9, 2020 13:20
-
-
Save amk221/6aed5df10cbd4a4888ac9c991e5949e2 to your computer and use it in GitHub Desktop.
Destroy record
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RESTAdapter from '@ember-data/adapter/rest'; | |
import { A as emberA } from '@ember/array'; | |
// Foos on the Server | |
let foos = emberA([{ | |
id: '1', | |
name: 'Foo 1' | |
}, { | |
id: '2', | |
name: 'Foo 2' | |
}]) | |
export default RESTAdapter.extend({ | |
ajax(path, method) { | |
if (method === 'GET') { | |
return { foos } | |
} | |
if (method === 'DELETE') { | |
const [id] = path.match(/\d+/); | |
const foo = foos.find(foo => foo.id === id); | |
// foos.removeObject(foo); | |
return null | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
import { action } from '@ember/object'; | |
export default class ApplicationController extends Controller { | |
@action | |
destroyFoo(foo) { | |
foo.destroyRecord(); | |
} | |
@action | |
reloadModel() { | |
this.refresh(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
export default class extends Model { | |
@attr() name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Route from '@ember/routing/route'; | |
import { inject } from '@ember/service'; | |
export default Route.extend({ | |
store: inject(), | |
model() { | |
return this.store.query('foo', { q: 'test' }); | |
}, | |
setupController(controller) { | |
controller.refresh = this.refresh.bind(this); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.0", | |
"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.3.1/jquery.js", | |
"ember": "3.17.0", | |
"ember-template-compiler": "3.17.0", | |
"ember-testing": "3.17.0" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-data": "3.17.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment