Last active
August 29, 2015 14:01
-
-
Save terion-name/0ec6097bfc2a42262100 to your computer and use it in GitHub Desktop.
Ember extractors for REST when backend returns data wrapped in "data" object, not in model name and "pagination" as a payload field
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.Store = DS.Store.extend | |
revision: 1, | |
adapter: DS.RESTAdapter.extend | |
namespace: 'api' | |
App.ApplicationSerializer = DS.RESTSerializer.extend | |
extractMeta: (store, type, payload)-> | |
if payload && payload.pagination | |
store.metaForType type, payload.pagination | |
delete payload.pagination | |
extractArray: (store, type, payload, id, requestType)-> | |
if payload && payload.data | |
key = Ember.Inflector.inflector.pluralize type.typeKey | |
payload[key] = payload.data | |
delete payload.data | |
@_super store, type, payload, id, requestType | |
extractSingle: (store, type, payload, id, requestType)-> | |
if payload && payload.data | |
key = Ember.Inflector.inflector.singularize type.typeKey | |
payload[key] = payload.data | |
delete payload.data | |
@_super store, type, payload, id, requestType |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment