-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the Serializer API #3143
Conversation
@wecc you forgot to mention JSON2Serializer |
I'm probably missing something, but why not naming those classes as JSONAPIXxx ? |
I think the fear is that |
@bmac Thanks, that makes sense |
|
||
function coerceId(id) { | ||
return id == null ? null : id + ''; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this method is repeated in the rest2-serializer
rest-serializer
and store
module. Lets move it into its own file and import it in all 3 places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
3d81d51
to
32072fd
Compare
cbb1a47
to
5c93d60
Compare
return this.normalizeDeleteRecordResponse(...arguments); | ||
case 'updateRecord': | ||
return this.normalizeUpdateRecordResponse(...arguments); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default to return this._normalizeResponse(...arguments)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could also dry this up to this['normalize' + capitalize(requestType)] || this._normalizeResponse)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have this vague memory that we wanted to change this to switch to make it easier for people to see what actual requestType
s are getting passed. We just never got around to change it here. The discussion was originally around https://github.com/emberjs/data/blob/master/packages/ember-data/lib/adapters/build-url-mixin.js#L52-L75
1028aa6
to
5fac1e8
Compare
👍 on structuring the commits |
ea0da9a
to
fe621bb
Compare
}, | ||
|
||
/** | ||
Returns the resource's relationships formatted as an JSON-API "relationships object". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/an/a/
a02a530
to
053f227
Compare
|
||
var ids = []; | ||
hash[key] = embeddedRecord.id; | ||
//TODO Need to add a reference to the parent later so relationship works between both `belongsTo` records |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this todo anymore
👍 |
b8a25ae
to
e3c3796
Compare
This PR refactors the way serializers normalizes adapter responses.
serializer.extract()
is now deprecated for the newserializer.normalizeResponse()
.normalizeResponse()
is expected to return a JSON-API Document with primary and, if any, secondary/sideloaded/included as{ data, included }
.normalize()
is also expected to return a JSON-API Document having the primary data be the normalized record in{ data }
and, if any, secondary data (e.g. embedded) in{ included }
.This change should be fully backwards compatible. For users to opt-in to the new Serializer API they should convert their existing
extract()
hooks tonormalizeResponse()
hooks and make it return JSON-API. Then addisNewSerializerAPI: true
in their serializer(s).Todos
REST2Serializer
,EmbeddedRecords2Mixin
andActiveModel2Serializer
to something that makes senseisNewSerializerAPI
for non-extended serializersnormalizeResponse()
normalizeResponse()
to reflect the oldextractArray/extractSingle
methods