This is a very trivial example of using mirage with Ember Twiddle.
Last active
January 10, 2019 23:14
-
-
Save shidel-dev/96bf17675f3a54913ae15610729bb1ac to your computer and use it in GitHub Desktop.
Ember Twiddle Demo: Mirage with Ember Twiddle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return this.get("store").createRecord("child").save(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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