Skip to content

Instantly share code, notes, and snippets.

@pgengler
Last active April 17, 2023 04:49
Show Gist options
  • Save pgengler/83ed7772daf1e60dc48f216a6674b5b6 to your computer and use it in GitHub Desktop.
Save pgengler/83ed7772daf1e60dc48f216a6674b5b6 to your computer and use it in GitHub Desktop.
ember-data unload issue 3.28
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class extends Component {
@service router;
@action async delete() {
const a = this.args.a;
const b = a.b;
await a.destroyRecord();
this.router.transitionTo('b', b.get('id'));
}
}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
import Model, { belongsTo } from '@ember-data/model';
export default class extends Model {
@belongsTo b;
}
import Model, { attr, hasMany } from '@ember-data/model';
export default class extends Model {
@hasMany a;
}
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('a', { path: '/a/:id' });
this.route('b', { path: '/:id' });
});
export default Router;
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class ARoute extends Route {
@service store;
model({ id }) {
return this.store.peekRecord('a', id);
}
}
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class extends Route {
@service store;
beforeModel() {
const b = this.store.createRecord('b', { id: 1 });
this.store.createRecord('a', { id: 1, b, title: 'Foo' });
this.store.createRecord('a', { id: 2, b, title: 'Bar' });
this.store.createRecord('a', { id: 3, b, title: 'Baz' });
}
}
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class BRoute extends Route {
@service store;
model({ id }) {
return this.store.peekRecord('b', id);
}
}
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class IndexRoute extends Route {
@service router;
@service store;
beforeModel() {
const bs = this.store.peekAll('b');
this.router.transitionTo('b', bs.firstObject.id);
}
}
<MyComponent @a={{@model}} />
<h1>"B" index</h1>
<ul>
{{#each @model.a as |a|}}
<li>
<LinkTo @route="a" @model={{a.id}}>{{a.title}}</LinkTo>
</li>
{{/each}}
</ul>
{{@a.title}}
<button type="button" {{on "click" this.delete}}>Delete</button>
{
"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.28.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment