Skip to content

Instantly share code, notes, and snippets.

@piotrpalek
Last active October 21, 2017 11:47
Show Gist options
  • Save piotrpalek/10ba43dbead9dbf2159b4607f6601e1e to your computer and use it in GitHub Desktop.
Save piotrpalek/10ba43dbead9dbf2159b4607f6601e1e 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 DS from 'ember-data';
export default DS.RESTAdapter.extend({});
import Ember from 'ember';
export default Ember.Controller.extend({
init() {
this._super(...arguments);
console.log('asdf');
console.log(this.get('model'));
window.q = this;
}
});
import Collection from 'ember-cli-mirage/orm/collection';
import Mirage from 'ember-cli-mirage';
export default function() {
window.server = this;
this.get('/foos', function (schema, request) {
return new Mirage.Response(422, {
'Content-Type': 'application/json'
},
{
errors: [{
author: ['name is invalid']
}]
});
});
};
import { RestSerializer } from 'ember-cli-mirage';
export default RestSerializer;
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
author: attr()
});
import Ember from 'ember';
export default Ember.Route.extend({
store: Ember.inject.service(),
model() {
return this.get('store').findAll('foo');
}
});
import DS from 'ember-data';
export default DS.RESTSerializer.extend({});
<header>
<h1>Mirage</h1>
</header>
{{model.firstObject.author}}
{
"version": "0.11.3",
"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.16.1",
"ember-template-compiler": "2.12.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