Skip to content

Instantly share code, notes, and snippets.

@riklomas
Forked from sukima/controllers.application.js
Last active May 21, 2019 22:03
Show Gist options
  • Save riklomas/e16f3cbcf957ad9767a23ba205d45d11 to your computer and use it in GitHub Desktop.
Save riklomas/e16f3cbcf957ad9767a23ba205d45d11 to your computer and use it in GitHub Desktop.
testing on twiddle
import Controller from '@ember/controller';
import { reads } from '@ember/object/computed';
export default Controller.extend({
children: reads('model'),
actions: {
clickChild(child) {
child.parent.then(parent => {
console.log(parent.name);
});
}
}
});
export default function() {
this.resource('message-thread');
this.resource('message-message');
this.resource('user');
}
import { Factory } from 'ember-cli-mirage';
export default Factory.extend({
name(i) { return `Message message-${i}`; }
});
import { Factory } from 'ember-cli-mirage';
export default Factory.extend({
name(i) { return `Thread-${i}`; }
});
import { Factory } from 'ember-cli-mirage';
export default Factory.extend({
name(i) { return `User-${i}`; }
});
export default function(server) {
let messageThread = server.create('message-thread');
let messageThread2 = server.create('message-thread');
let user = server.create('user');
server.createList('message-message', 10, { messageThread, user });
server.createList('message-message', 10, { messageThread: messageThread2, user });
}
import { JSONAPISerializer } from 'ember-cli-mirage';
export default JSONAPISerializer.extend({
alwaysIncludeLinkageData: true,
});
import DS from 'ember-data'
const {Model, attr, hasMany, belongsTo} = DS
export default DS.Model.extend({
messageThread: belongsTo('message-thread', { async: true }),
user: belongsTo("user", {async: true}),
name: attr(),
});
import DS from 'ember-data'
const {Model, attr, hasMany, belongsTo} = DS
export default DS.Model.extend({
messageMessages: hasMany({ async: true }),
name: attr(),
});
import DS from 'ember-data'
const {Model, attr, hasMany} = DS
export default Model.extend({
name: attr(),
messageMessages: hasMany(),
});
import Route from '@ember/routing/route';
export default Route.extend({
model() {
return this.store.findAll('message-thread');
}
});
{{#each model as |thread|}}
<h1>Thread {{thread.id}}</h1>
{{#each thread.messageMessages as |message|}}
<p>
<strong>{{message.name}}</strong>
{{message.user.name}}
</p>
{{/each}}
{{/each}}
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"ENV": {
"ember-cli-mirage": {
"enabled": true
}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.9.0",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.11.0",
"ember-cli-mirage": "0.4.6"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment