This is a very trivial example of using mirage with Ember Twiddle.
Last active
May 27, 2018 13:26
-
-
Save sbatson5/d2c4057c04aad43755fe6a27d8464c64 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'; | |
const { computed, get, set } = Ember; | |
export default Ember.Component.extend({ | |
tagName: 'form', | |
noName: computed.empty('model.name'), | |
cannotSubmit: computed.or('noName', 'activePromise.isPending'), | |
submit(event) { | |
event.preventDefault(); | |
let promise = get(this, 'model').save(); | |
set(this, 'activePromise', promise); | |
}, | |
actions: { | |
setValue(nameValue) { | |
set(this, 'model.name', nameValue); | |
} | |
} | |
}); |
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'; | |
import { Response } from 'ember-cli-mirage'; | |
export default function() { | |
window.server = this; | |
this.timing = 1000; | |
this.post('/foos', function (schema, { requestBody }) { | |
let { name } = JSON.parse(requestBody).data.attributes; | |
if (name == 'success') { | |
return new Response(204); | |
} else { | |
return new Response(422); | |
} | |
}); | |
}; |
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({ | |
name: attr('string') | |
}); |
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('foo', { id: 1 }); | |
} | |
}); |
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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
button { | |
text-decoration: none; | |
color: #fff; | |
background-color: #26a69a; | |
text-align: center; | |
letter-spacing: .5px; | |
width: 50%; | |
font-size: 150%; | |
height: 50px; | |
} | |
button:disabled { | |
background-color: #888; | |
} |
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
{ | |
"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.11.0", | |
"ember-data": "2.11.0", | |
"ember-template-compiler": "2.11.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