Skip to content

Instantly share code, notes, and snippets.

@juarezpaf
Forked from richardkall/store.coffee
Created August 2, 2013 06:41
Show Gist options
  • Save juarezpaf/6137919 to your computer and use it in GitHub Desktop.
Save juarezpaf/6137919 to your computer and use it in GitHub Desktop.
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