-
Notifications
You must be signed in to change notification settings - Fork 55
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
PaginatedResource API change #28
Comments
Goit := presence.Get(params)
for it.Next() {
page := it.PresenceMessages()
for _, item := range page {
fmt.Println(item)
}
}
if err := it.Err(); err != nil {
panic(err)
} |
@rjeczalik so that looks good although I think it is wrong because a) I expect it will therefore look more like this unfortunately: currentPage, err := presence.Get(params)
for {
if err != nil {
panic(err)
}
if currentPage == nil {
break
}
for _, item := range currentPage.items {
fmt.Println(item)
}
currentPage, err = currentPage.Next()
} With my example I am not sure how the page would return an error though, you may need to advise on the best way of doing this. |
(in advance sorry for lengthy post and no TL;DR) @mattheworiordan Depends what our priorities are:
page, err := presence.Get(params)
for ; err == nil; page, err = page.Next() {
for _, item := range page.Items() {
fmt.Println(item)
}
}
if err != nil {
panic(err)
}
In order to make it idiomatic, the most important difference is to store the error within the And addressing questions:
On the first iteration
Yup, the Go
Yup, the way I intend the iterator to work is to mutate itself to the next page, so
var i, itemsFrom3rdPage = 0, []interface{}(nil)
for page.Next() {
items := page.Items()
if i++; i == 3 {
itemsFrom3rdPage = items
}
// as items does not mutate between iterations, it can be handled async
go fmt.Println(items)
}
if err := page.Err(); err != nil {
panic(err)
}
fmt.Println(itemsFrom3rdPage)
var i, page3rd = 0, (*ably.PaginatedResource)(nil)
for page.Next() {
items := page.Items()
if i++; i == 3 {
page3rd = page.Ref() // or page.Clone()
}
// as items does not mutate between iterations, it can be handled async
go fmt.Println(items)
}
if err := page.Err(); err != nil {
panic(err)
}
for page3rd.Next() {
// continue ranging after 3rd page
} @mattheworiordan @kouno The call is not mine, let me know guys which one, 1) or 2) you prefer to have. |
When a query is performed, various of the params are typically unspecified, but are then resolved to specific values when the query is evaluated; eg |
@paddybyers Yup, the After rethinking this I withdrawn my statement that my proposed second approach is more idiomatic than the first one - traversing the pages as they were nodes is also fine. I'd just remove the wrappers that each function in rest / realtime client wraps |
👍 sounds awesome. |
@rjeczalik sounds reasonable, but I think it's important that we don't make PaginatedResource an iterator to iterate through pages. Other languages for various reasons can't really do that, especially Javascript, so we'd prefer to keep the behaviour as similar as possible between languages, so Next() or First() should return a |
@mattheworiordan Yup, crystal clear, I settled on exactly that. |
According to ably/ably-js#28.
According to ably/ably-js#28.
According to ably/ably-js#28.
According to ably/ably-js#28.
See ably/ably-js#28 where the new API is discussed for PaginatedResource. This is a client library API breaking change. Note: * PaginatedResource no longer has #next_page, #last_page but instead simply has #next, #last * Additional predicate method #has_next? has been added * All items are no longer accessible from the PaginatedResource object itself, but instead are accessible through the #items Array attribute. This change will help developers to understand that history & stats requests returned paged objects.
@paddybyers, @rjeczalik and @kouno, I have implemented this feature in the Ruby API as I wanted to see what was involved. It didn't take very long, see https://github.com/ably/ably-ruby/tree/new-paginated-resource. I find the API is now a bit more verbose, but equally I think conceptually it's a lot clearer what developers are dealing with when accessing paged results. See https://github.com/ably/ably-ruby/pull/26/files#diff-04c6e90faac2675aa89e2176d2eec7d8 for a description of how it's changed in the Readme. What do you think? |
I think the iOS pagination is what you want. You get a ARTPaginatedResult back,
|
@thevixac thanks for the post. I think the iOS API looks very close in fact. However, the key difference is that instead of providing the attribute |
See ably/ably-js#28 where the new API is discussed for PaginatedResource. This is a client library API breaking change. Note: * PaginatedResource no longer has #next_page, #last_page but instead simply has #next, #last * Additional predicate method #has_next? has been added * All items are no longer accessible from the PaginatedResource object itself, but instead are accessible through the #items Array attribute. This change will help developers to understand that history & stats requests returned paged objects.
See ably/ably-js#28 where the new API is discussed for PaginatedResource.
I've got two alternative implementations in javascript. The first uses the fact that there is a callback that can return multiple results to return the items and the rel links in two separate callback arguments:
The second API more closely follows the generic proposal, where a single
|
Given the second is closer to other implementations I think that is best. Are you looking for confirmation before one is implemented? |
I've implemented both, but I prefer the first :) |
Ah, ok, thanks. |
I don't think this is working unfortunately. Here is some code I am using to get history: channel.history(limit: 1000, function (err, messages) {
console.log(err); // => null
console.log(messages.items); // => null
console.log(messages.length); // => 2
}); Is the common API active? It seems like it is defaulting to the |
No, I implemented two versions of the API but neither got merged yet. |
Ok, can we merge? |
This is merged now in 0.8.1 |
Thanks, is 0.8.1 deployed to the CDN & NPM? |
CDN yes, NPM no. |
Ok, published to |
Whilst our client APIs are consistent, the
PaginatedResource
API has unfortunately diverged somewhat. Following some discussions, we have decided to implement thePaginatedResource
so that it is iterator-like, provides an accessor / method to the items it holds to encourage understanding of the pages of results concept to developers i.e. each next page is a new request for new items, and provides similar synchronous and asynchronous interfaces.The proposed interface demonstrated in code is therefore as follows:
Async Javascript
Sync Ruby
The text was updated successfully, but these errors were encountered: