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

[FEATURE ds-serialize-id] add serializeId to json-serializer #4620

Merged
merged 1 commit into from
Oct 23, 2016

Conversation

Romanior
Copy link
Contributor

addresses #4477

@@ -1073,6 +1069,21 @@ var JSONSerializer = Serializer.extend({
},

/**
SerializeId can be used to customize how 'Id' is seriaziled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SerializeId => serializeId
'Id' => id
seriaziled => serialized

Can we expand this with a use-case and example? I've seen a couple of issues where people want to cast the ID to a Number – that might be a good example.

@@ -68,6 +68,20 @@ test("serialize includes id when includeId is true", function(assert) {
});
});

test("serializeId", function(assert) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add another test and call serialize() with a customized serializeId() and assert that serializeId() is actually called from serialize()

Copy link
Member

@pangratz pangratz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this adds a new method to the public API, this needs to go behind a feature flag. See the section in the CONTRIBUTING.md on how to do that. I would suggest ds-serialize-id for the feature name.

You can also take a look at #4110 for a sample PR which implements a feature.

Spasibo!

Copy link
Member

@pangratz pangratz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test coverage!

A few tiny nitpicks, then this is good to go! 🚀

var id = snapshot.id;
json[primaryKey] = parseInt(id, 10);
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nitpick but can you adapt the indentation of the code sample? Thanks!

serializeId(snapshot, json, primaryKey) {
var id = snapshot.id;

if (id && primaryKey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the check for primaryKey can be removed. This would then be symmetric to the implementation when this feature is not enabled.

var id = snapshot.id;
json[primaryKey] = parseInt(id, 10);
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation


/**
serializeId can be used to customize how id is serialized

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to outline the default implementation. Something along the lines of:

By default the snapshots' id(which is a String) will be set on the json hash via json[primaryKey] = snapshot.id.

@pangratz
Copy link
Member

While you're at it, can you prefix the commit as [BUGFIX ds-serialize-id]. Thanks!

@Romanior Romanior force-pushed the add-serializeId branch 3 times, most recently from 87cc598 to f3119e5 Compare October 23, 2016 13:48
@pangratz
Copy link
Member

Sorry, with [BUGFIX ds-serialize-id] I meant actually [FEATURE ds-serialize-id]

@Romanior Romanior changed the title [FEATURE serializeId] add serializeId to json-serializer [FEATURE ds-serialize-id] add serializeId to json-serializer Oct 23, 2016
@pangratz pangratz merged commit 61dbaeb into emberjs:master Oct 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants