Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
config: attr(),
versions: attr()
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('route', function () {
});
});
export default Router;
import Ember from 'ember';
var server = new Pretender(function () {
this.get("/my-models/1", function () {
return [200, {}, JSON.stringify({
"my-model": {
id: 1,
versions: [{version: 1}, {version: 2}, {version: 3}]
}
})
]
});
});
export default Ember.Route.extend({
model () {
return this.store.findRecord('my-model', 1).then((record) => {
console.log('found', record);
return record;
});
}
});
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
normalizeResponse(store, modelclass, payload, id) {
return {
data: {
id,
attributes: {
config: payload['my-model'].versions[0],
versions: payload['my-model'].versions.slice(1)
},
type: modelclass.modelName
}
};
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{#link-to 'route'}}Route{{/link-to}}
<br>
<br>
<h1>MY route</h1>
{{#link-to 'application'}}application{{/link-to}}
{
"version": "0.13.0",
"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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2",
"route-recognizer": "https://rawgit.com/tildeio/route-recognizer/56f5fcec6ae58d8e86b5dc77609809fb91198142/dist/route-recognizer.js",
"FakeXMLHttpRequest": "https://rawgit.com/pretenderjs/FakeXMLHttpRequest/23c3a96b5b24f1bfe595867437e4f128a29c2840/fake_xml_http_request.js",
"pretender": "https://rawgit.com/pretenderjs/pretender/c6de9afe18b1472aded2592f5a80ad9a26a0e262/pretender.js"
},
"addons": {
"ember-data": "2.18.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.