Feature #2504

asynchronous paginator

Added by Anatoly Shcherbinin over 4 years ago. Updated over 4 years ago.

Status:FixedStart date:01/19/2015
Priority:NormalDue date:
Assignee:Andreas Smas% Done:

100%

Category:Ecmascript & Duktape
Target version:4.10

Description

In 4.8 we have duktape engine with asynchronous http request. Unfortunately page's paginator should make request synchronously.
So we need asynchronous paginator.
It should have callback function as argument. Calling that method will let showtime know that asynch paginator is performed and have more or have no more items.
For example:

            (page.paginator = function(haveMore)
            {
                page.loading = true;
                showtime.httpReq("https://api.vk.com/method/video.getAlbums", {args:{
                    owner_id:owner_id,
                    access_token:access_token,
                    v:5.23,
                    offset:offset,
                    count:30,
                    extended:1
                }}, function(err, respData)
                {
                var response = showtime.JSONDecode(respData.toString()).response;
                var items = response.items;
                if (0 == items.length)
                {
                    page.loading = false;
                    haveMore(false);
                    return;
                }
                for (var i in items)
                {
                    var item = items[i];
                    page.appendItem(PLUGIN_NAME + ":videos:" + id + ":" + item.id, 'video', {title:item.title, icon:item.photo_320,
                        description:new showtime.RichText(richTxt(item.title, {size:5,color:titleClr})+richTxt("\n\nCount: "+item.count,{size:4,color:textClr}))});
                }
                offset += items.length;
                page.loading = false;
                haveMore(true);
            }})();

Associated revisions

Revision a1c93366
Added by Andreas Smas over 4 years ago

ecmascript/page: Add asynchronous paginator

Fixes #2504

Change included in version 4.9.105

History

#1 Updated by Andreas Smas over 4 years ago

  • Status changed from New to Accepted
  • Target version set to 4.10

Yes I thought about this the other day.

Well spotted :-)

#2 Updated by Andreas Smas over 4 years ago

I think I should also rewrite some plugin to utilize this.

#3 Updated by Andreas Smas over 4 years ago

Passing 'haveMore()' as a callback to the paginator comes with a problem though. There's no way to initially tell about if there are more items available.

#4 Updated by Andreas Smas over 4 years ago

  • Status changed from Accepted to Fixed
  • % Done changed from 0 to 100

#5 Updated by Andreas Smas over 4 years ago

As you can see the fix is very simple

Just assign page.asyncPaginator = function() {

};

and then do "page.haveMore(true / false)"

You can see this commit: https://github.com/andoma/showtime-plugin-headweb/commit/b284da55ecee60fe0bae0585bfdf912a8db1fd4a how i added it to the headweb plugin

#6 Updated by Anatoly Shcherbinin over 4 years ago

Good news. Thanks. AsyncPaginator works great. New items get loaded before user get to end of the list and no more problem jumping selected item to the list beginning.

Also available in: Atom PDF