Created
August 18, 2016 13:04
-
-
Save rlivsey/f8f8859a5fb03bb7164b86b576ff483c to your computer and use it in GitHub Desktop.
push payload
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 JSONAPIAdapter from 'ember-data/adapters/json-api'; | |
export default JSONAPIAdapter.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 Ember from 'ember'; | |
var data = { | |
data: { | |
type: 'person', | |
id: 'p-1', | |
attributes: { | |
name: 'Some Person' | |
}, | |
relationships: { | |
company: { | |
data: { | |
id: 'c-1', | |
type: "company" | |
} | |
} | |
} | |
}, | |
included: [{ | |
id: 'c-1', | |
type: "company", | |
attributes: { | |
name: "Foo Corp" | |
}, | |
relationships: { | |
addresses: { | |
data: [{ | |
id: 'a-1', | |
type: "company/address" | |
}, { | |
id: 'a-2', | |
type: "company/address" | |
}] | |
} | |
} | |
}, { | |
id: 'a-1', | |
type: "company/address", | |
attributes: { | |
name: "Some Place" | |
} | |
}, { | |
id: 'a-2', | |
type: "company/address", | |
attributes: { | |
name: "Some Other Place" | |
} | |
}] | |
}; | |
export default Ember.Controller.extend({ | |
store: Ember.inject.service(), | |
actions: { | |
simulateUpdate() { | |
Ember.run.later(this, function() { | |
this.get("store").pushPayload(clone(data)); | |
}, 1000); | |
} | |
} | |
}); | |
function clone(obj) { | |
return JSON.parse(JSON.stringify(obj)); | |
} |
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 function now() { | |
return performance.now(); | |
} | |
export default Ember.Helper.helper(now); |
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
export function returnJSON(status, body) { | |
return json(...arguments); | |
}; | |
export function json(status, body) { | |
if (arguments.length === 1) { | |
body = status; | |
status = 200; | |
} | |
return [ | |
status, | |
{ "Content-Type": "application/json" }, | |
JSON.stringify(body) | |
]; | |
}; | |
export const server = new Pretender(); | |
export function initialize() { | |
server.handledRequest = function(verb, path, request) { | |
console.log(`handled request to ${verb} ${path}`); | |
} | |
server.unhandledRequest = function(verb, path, request) { | |
console.log(`undhandled request ${verb} ${path}`); | |
} | |
}; | |
export default { | |
name: 'pretender', | |
initialize | |
}; |
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() | |
}); |
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(), | |
addresses: hasMany("company/address") | |
}); |
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(), | |
company: belongsTo("company") | |
}); |
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'; | |
import { server, json } from '../initializers/pretender'; | |
server.map(function() { | |
this.get('/people/p-1', function() { | |
return json({ | |
data: { | |
type: 'person', | |
id: 'p-1', | |
attributes: { | |
name: 'Some Person' | |
}, | |
relationships: { | |
company: { | |
data: { | |
id: 'c-1', | |
type: "company" | |
} | |
} | |
} | |
}, | |
included: [{ | |
id: 'c-1', | |
type: "company", | |
attributes: { | |
name: "Foo Corp" | |
}, | |
relationships: { | |
addresses: { | |
data: [{ | |
id: 'a-1', | |
type: "company/address" | |
}] | |
} | |
} | |
}, { | |
id: 'a-1', | |
type: "company/address", | |
attributes: { | |
name: "Some Place" | |
} | |
} | |
] | |
}); | |
}); | |
}); | |
export default Ember.Route.extend({ | |
store: Ember.inject.service(), | |
model() { | |
return this.get("store").findRecord("person", 'p-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
{ | |
"version": "0.10.4", | |
"EmberENV": { | |
"FEATURES": { | |
"ds-pushpayload-return": true, | |
"ds-extended-errors": true | |
} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "canary", | |
"ember-data": "canary", | |
"ember-template-compiler": "canary", | |
"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": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment