Skip to content

Instantly share code, notes, and snippets.

@0000marcell
Created January 5, 2017 22:24
Show Gist options
  • Save 0000marcell/8101bfe5949c6cf9fc2da0ac41166304 to your computer and use it in GitHub Desktop.
Save 0000marcell/8101bfe5949c6cf9fc2da0ac41166304 to your computer and use it in GitHub Desktop.
Mirage-Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Test'
});
export default function() {
//window.server = this;
this.get('/authors');
this.get('/authors/:id');
this.get('/books');
this.get('/books/:id');
};
import { Factory } from 'ember-cli-mirage';
export default Factory.extend({
name: 'Marcell Monteiro Cruz'
});
import { Factory } from 'ember-cli-mirage';
export default Factory.extend({
name: 'book'
});
import { Model, hasMany } from 'ember-cli-mirage';
export default Model.extend({
books: hasMany('book')
});
import { Model } from 'ember-cli-mirage';
export default Model.extend({
});
export default function(server) {
// added this line because global wasn't created otherwise.
let author = server.create('author');
let books = server.createList('book', 10);
author.books = books;
}
import { JSONAPISerializer } from 'ember-cli-mirage';
export default JSONAPISerializer.extend({
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
name: attr('string'),
books: hasMany('book')
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
export default Model.extend({
name: attr('string')
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model(){
return this.store.find('author', 1);
}
});
<h1>Authors</h1>
{{#each model.books as |book|}}
<p>{{book.name}}</p>
{{/each}}
{
"version": "0.10.7",
"ENV": {
"ember-cli-mirage": {
"enabled": true
}
},
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.0",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0"
},
"addons": {
"ember-cli-mirage": "0.2.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment