Skip to content
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

During normalization, use property lookup instead of hasOwnProp checks #4393

Merged
merged 1 commit into from
May 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addon/serializers/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ const JSONAPISerializer = JSONSerializer.extend({
if (resourceHash.attributes) {
modelClass.eachAttribute((key) => {
let attributeKey = this.keyForAttribute(key, 'deserialize');
if (resourceHash.attributes.hasOwnProperty(attributeKey)) {
if (resourceHash.attributes[attributeKey] !== undefined) {
attributes[key] = resourceHash.attributes[attributeKey];
}
});
Expand Down Expand Up @@ -307,7 +307,7 @@ const JSONAPISerializer = JSONSerializer.extend({
if (resourceHash.relationships) {
modelClass.eachRelationship((key, relationshipMeta) => {
let relationshipKey = this.keyForRelationship(key, relationshipMeta.kind, 'deserialize');
if (resourceHash.relationships.hasOwnProperty(relationshipKey)) {
if (resourceHash.relationships[relationshipKey] !== undefined) {

let relationshipHash = resourceHash.relationships[relationshipKey];
relationships[key] = this.extractRelationship(relationshipHash);
Expand Down
18 changes: 9 additions & 9 deletions addon/serializers/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ var JSONSerializer = Serializer.extend({

modelClass.eachAttribute((key) => {
attributeKey = this.keyForAttribute(key, 'deserialize');
if (resourceHash.hasOwnProperty(attributeKey)) {
if (resourceHash[attributeKey] !== undefined) {
attributes[key] = resourceHash[attributeKey];
}
});
Expand Down Expand Up @@ -659,7 +659,7 @@ var JSONSerializer = Serializer.extend({
modelClass.eachRelationship((key, relationshipMeta) => {
let relationship = null;
let relationshipKey = this.keyForRelationship(key, relationshipMeta.kind, 'deserialize');
if (resourceHash.hasOwnProperty(relationshipKey)) {
if (resourceHash[relationshipKey] !== undefined) {
let data = null;
let relationshipHash = resourceHash[relationshipKey];
if (relationshipMeta.kind === 'belongsTo') {
Expand All @@ -685,7 +685,7 @@ var JSONSerializer = Serializer.extend({
}

let linkKey = this.keyForLink(key, relationshipMeta.kind);
if (resourceHash.links && resourceHash.links.hasOwnProperty(linkKey)) {
if (resourceHash.links && resourceHash.links[linkKey] !== undefined) {
let related = resourceHash.links[linkKey];
relationship = relationship || {};
relationship.links = { related };
Expand Down Expand Up @@ -721,7 +721,7 @@ var JSONSerializer = Serializer.extend({
typeClass.eachAttribute((key) => {
payloadKey = this.keyForAttribute(key, 'deserialize');
if (key === payloadKey) { return; }
if (!hash.hasOwnProperty(payloadKey)) { return; }
if (hash[payloadKey] === undefined) { return; }

hash[key] = hash[payloadKey];
delete hash[payloadKey];
Expand All @@ -740,7 +740,7 @@ var JSONSerializer = Serializer.extend({
typeClass.eachRelationship((key, relationship) => {
payloadKey = this.keyForRelationship(key, relationship.kind, 'deserialize');
if (key === payloadKey) { return; }
if (!hash.hasOwnProperty(payloadKey)) { return; }
if (hash[payloadKey] === undefined) { return; }

hash[key] = hash[payloadKey];
delete hash[payloadKey];
Expand All @@ -760,7 +760,7 @@ var JSONSerializer = Serializer.extend({
for (key in attrs) {
normalizedKey = payloadKey = this._getMappedKey(key, modelClass);

if (!hash.hasOwnProperty(payloadKey)) { continue; }
if (hash[payloadKey] === undefined) { continue; }

if (get(modelClass, 'attributes').has(key)) {
normalizedKey = this.keyForAttribute(key);
Expand Down Expand Up @@ -1273,7 +1273,7 @@ var JSONSerializer = Serializer.extend({
@param {Object} payload
*/
extractMeta(store, modelClass, payload) {
if (payload && payload.hasOwnProperty('meta')) {
if (payload && payload['meta'] !== undefined) {
let meta = payload.meta;
delete payload.meta;
return meta;
Expand Down Expand Up @@ -1373,15 +1373,15 @@ var JSONSerializer = Serializer.extend({

typeClass.eachAttribute((name) => {
let key = this.keyForAttribute(name, 'deserialize');
if (key !== name && payload.hasOwnProperty(key)) {
if (key !== name && payload[key] !== undefined) {
payload[name] = payload[key];
delete payload[key];
}
});

typeClass.eachRelationship((name) => {
let key = this.keyForRelationship(name, 'deserialize');
if (key !== name && payload.hasOwnProperty(key)) {
if (key !== name && payload[key] !== undefined) {
payload[name] = payload[key];
delete payload[key];
}
Expand Down
2 changes: 1 addition & 1 deletion addon/serializers/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ var RESTSerializer = JSONSerializer.extend({
var isPolymorphic = relationshipMeta.options.polymorphic;
var typeProperty = this.keyForPolymorphicType(key, relationshipType, 'deserialize');

if (isPolymorphic && resourceHash.hasOwnProperty(typeProperty) && typeof relationshipHash !== 'object') {
if (isPolymorphic && resourceHash[typeProperty] !== undefined && typeof relationshipHash !== 'object') {

if (isEnabled("ds-payload-type-hooks")) {

Expand Down