Last active
December 3, 2023 22:08
-
-
Save richardkall/5910875 to your computer and use it in GitHub Desktop.
Ember.js REST adapter without JSON root element.
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
App.Adapter = DS.RESTAdapter.extend | |
serializer: DS.RESTSerializer.extend | |
extract: (loader, json, type, record) -> | |
root = @rootForType(type) | |
// Embed JSON data in a new object with root element | |
newJSON = {} | |
newJSON[root] = json | |
json = newJSON | |
// | |
@sideload loader, type, json, root | |
@extractMeta loader, type, json | |
if json[root] | |
loader.updateId record, json[root] if record | |
@extractRecordRepresentation loader, type, json[root] | |
else | |
Ember.Logger.warn "Extract requested, but no data given for " + type + ". This may cause weird problems." | |
extractMany: (loader, json, type, records) -> | |
root = @rootForType(type) | |
root = @pluralize(root) | |
// Embed JSON data in a new object with root element | |
newJSON = {} | |
newJSON[root] = json | |
json = newJSON | |
// | |
@sideload loader, type, json, root | |
@extractMeta loader, type, json | |
if json[root] | |
objects = json[root] | |
references = [] | |
records = records.toArray() if records | |
i = 0 | |
while i < objects.length | |
loader.updateId records[i], objects[i] if records | |
reference = @extractRecordRepresentation(loader, type, objects[i]) | |
references.push reference | |
i++ | |
loader.populateArray references | |
App.Store = DS.Store.extend | |
revision: 12 | |
adapter: App.Adapter.create() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Coffee..... eh, I guess I'll convert it to normal javascript.