Skip to content

Instantly share code, notes, and snippets.

View components.my-component\.js
import Component from '@glimmer/component';
export default class extends Component {
}
View controllers.application\.js
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
@amk221
amk221 / adapters.foo\.js
Last active Aug 5, 2020
Embedded Records
View adapters.foo\.js
import RESTAdapter from 'ember-data/adapters/rest';
const { stringify } = JSON;
export default class FooAdapter extends RESTAdapter {
ajax(path, method, options) {
if (method === 'PUT' || method === 'POST') {
console.log(method, stringify(options.data, null, 2))
}
return {
@amk221
amk221 / adapters.bar\.js
Last active Jul 21, 2020
Ember Data promise proxy
View adapters.bar\.js
import RESTAdapter from 'ember-data/adapters/rest';
export default class FooAdapter extends RESTAdapter {
ajax(path, method, options) {
const id = path.match(/\d+/)[0];
return {
bar: {
id: id,
name: `Bar${id}`
}
View controllers.application\.js
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
View adapters.bar\.js
import RESTAdapter from 'ember-data/adapters/rest';
export default class FooAdapter extends RESTAdapter {
ajax(path, method, options) {
return {
bars: [{
id: 1,
name: 'Bar 1'
}, {
id: 2,
View adapters.foo\.js
// 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'
}, {
View controllers.application\.js
import Controller from '@ember/controller';
import { action } from '@ember/object';
export default class ApplicationController extends Controller {
@action
save() {
this.model.setProperties(this.changeset);
console.log(this.changeset.name)
console.log(this.model.name)
View components.my-child-component\.js
import Component from '@glimmer/component';
import { action } from '@ember/object';
export default class extends Component {
@action
handleInsert(element) {
// this.element = element;
this.foo = element;
}
@amk221
amk221 / adapters.person\.js
Last active Jun 4, 2020
Overwriting query #2
View adapters.person\.js
import RESTAdapter from '@ember-data/adapter/rest';
import { A as emberA } from '@ember/array';
import { later } from '@ember/runloop';
let count = 0;
let delay = 0;
export default RESTAdapter.extend({
ajax(path, method, options) {
count++;
You can’t perform that action at this time.