Skip to content

Instantly share code, notes, and snippets.

@shidel-dev
Last active January 10, 2019 23:14
Show Gist options
  • Save shidel-dev/96bf17675f3a54913ae15610729bb1ac to your computer and use it in GitHub Desktop.
Save shidel-dev/96bf17675f3a54913ae15610729bb1ac to your computer and use it in GitHub Desktop.
Ember Twiddle Demo: Mirage with Ember Twiddle

Ember Twiddle Demo: Mirage with Ember Twiddle

Demo

This is a very trivial example of using mirage with Ember Twiddle.

import Ember from 'ember';
export default Ember.Controller.extend({
});
import Collection from 'ember-cli-mirage/orm/collection';
export default function() {
window.server = this;
this.post('/children', function (schema, request) {
let json = {
data: {
id: "1",
type: "child",
attributes: {
id: "1",
name: "child1"
},
relationhips: {
parent: {
type: "adult",
id: "2"
}
},
},
included: [
{
id: "1",
type: "child",
attributes: {
id: "1",
name: "child1"
},
relationhips: {
parent: {
type: "adult",
id: "2"
}
},
}
]
}
return json;
});
};
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
parent: belongsTo("parent")
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
children: hasMany("children")
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get("store").createRecord("child").save();
}
});
<header>
<h1>Mirage</h1>
</header>
<ul>
{{#each model as |post|}}
<li>{{post.author.name}}</li>
{{/each}}
</ul>
{
"ENV": {
"ember-cli-mirage": {
"enabled": true
}
},
"EmberENV": {},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-data": "2.18.5",
"ember-template-compiler": "2.12.0"
},
"addons": {
"ember-cli-mirage": "0.3.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment