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

Refactor mechanism to deserialize user-defined classes for entries #138

Merged
merged 5 commits into from
Oct 10, 2017

Conversation

loudmouth
Copy link
Contributor

@loudmouth loudmouth commented Oct 9, 2017

TODO before merging:

Fixes #132
Fixes #133
Though not a direct fix for denormalizing the JSON response, the fact that the new mechanism leverages Swift 4's decodable protocol obviates the need to denormalize the json, therefore this fixes #109

@loudmouth loudmouth force-pushed the improvement/entry-decoding branch from 9bf3c91 to 92d5cdf Compare October 10, 2017 12:10
@loudmouth loudmouth force-pushed the improvement/entry-decoding branch from 92d5cdf to 271607e Compare October 10, 2017 12:59
Copy link

@dlitvakb dlitvakb left a comment

Choose a reason for hiding this comment

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

Some minor comments, no change required per se, but would be nice to check.

}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

Choose a reason for hiding this comment

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

Spacing on assignment is not consistent throughout the code. For example, within this same method: https://github.com/contentful/contentful.swift/pull/138/files#diff-0312db99a9cdde535bb9947197e97a8eR148

Either have all of them aligning, or have all of them with proper whitespace. I personally prefer having them with regular whitespacing as it's simpler to read at a glance, and extra whitespace is noisy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'll see what i can do! thanks @dlitvakb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so yeah, i'm simply aligning the right hand side for all these methods to the farthest left that they can be and still remained aligned. make sense?

Choose a reason for hiding this comment

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

sounds good

var entries: [EntryDecodable] = []
let contentTypes = decoder.userInfo[DecoderContext.contentTypesContextKey] as! [ContentTypeId: EntryDecodable.Type]

while entriesJSONContainer.isAtEnd == false {

Choose a reason for hiding this comment

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

while !entriesJSONContainer.isAtEnd {

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually like == false here. It's easy to miss the ! at the start and it gets especially confusing when you have a semantic variable like isAtEnd. Just my 2c.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, i've chosen as the style for the sdk to use == false always over !

Choose a reason for hiding this comment

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

I personally prefer conciseness, but I understand that it may get lost in the syntax.

var entries: [EntryDecodable] = []
let contentTypes = decoder.userInfo[DecoderContext.contentTypesContextKey] as! [ContentTypeId: EntryDecodable.Type]

while entriesJSONContainer.isAtEnd == false {

Choose a reason for hiding this comment

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

same as previous

Choose a reason for hiding this comment

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

Some of this code looks to be duplicated, may there be a way to de-duplicate and reuse it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unfortunately, these are different types and i'm just initializing a few mutable and immutable variables. i think the only refactor opportunity would be a helper that returns a tuple, but in fact the handling of data inside this json is different while iterating through the container.

var entries: [EntryDecodable] = []
let contentTypes = decoder.userInfo[DecoderContext.contentTypesContextKey] as! [ContentTypeId: EntryDecodable.Type]

while entriesJSONContainer.isAtEnd == false {

Choose a reason for hiding this comment

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

Same as previous

@loudmouth loudmouth merged commit ffff6cb into master Oct 10, 2017
@loudmouth loudmouth deleted the improvement/entry-decoding branch October 10, 2017 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants