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

Add Decode functionality for paging results #20

Merged
merged 3 commits into from
Nov 28, 2014
Merged

Add Decode functionality for paging results #20

merged 3 commits into from
Nov 28, 2014

Conversation

cbroglie
Copy link

No description provided.

@huandu
Copy link
Owner

huandu commented Nov 28, 2014

@cbroglie You should not store original res in PagingResult. The res won't be changed by PageResult. So if a result navigates to next or previous page, res and the result are not the same.

Regarding to the function PagingResult#Decode, it may not be necessary and that useful from my point of view.

Here is a convenient way to decode struct from PagingResult using current api.

res := Result{
    "data": pagingResult.Data(),
}
var friends FacebookFriends
err := res.Decode(&friends)

As you can see, res in the sample is a waste. Personally I don't recommend to decode struct in this way. It's better to use []Result returned by PagingResult#Decode() and decode result one by one.

@cbroglie
Copy link
Author

My original change was updating the result in navigate, so it did work. But I didn't realize Decode worked with a Result containing typed data, so your solution is simpler.

It's convenient to be able to decode the result into a single struct, instead of doing it each element at a time (that creates a lot of boiler plate code), so I would like to see PagingResult#Decode make it into the API.

@huandu
Copy link
Owner

huandu commented Nov 28, 2014

OK. I found my assertion was wrong. You did update res in navigation properly.

Since there is no single-line-solution to decode from []Result right now, I agree that PagingResult#Decode can save some time in some case.

Last but not least, thanks for your contribution.

huandu added a commit that referenced this pull request Nov 28, 2014
Add Decode functionality for paging results
@huandu huandu merged commit a5f6bc8 into huandu:master Nov 28, 2014
@cbroglie
Copy link
Author

Thanks! I appreciate your work on this project, it's serving me well.

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.

2 participants