Skip to content

Confirmation on how get descriptor prepend/append works #65

Closed
@MartyBolton

Description

@MartyBolton

So I'm using the get function with descriptor and append/prepend logic that we talked about in #63 and I have some weird jogging (race conditions) going on and I not sure if I'm interpreting the logic based on what is being called. I'm loading an object array lets call it posts and buffer size is 20. I should note that about 5 posts fit on a page, so I want to load up 20 at a time. It loads the first twenty fine, but when I scroll down, it looks like its calling for the next twenty which is correct, but immediately calls for the previous twenty starting from the current position -3 (which is the internal buffer overlap I guess).

So problem (a) - why do we need load the previous items that we already have?
Problem (b) seems to be this race condition where it calls get for the next twenty and previous 20 in a loop but offset each time. Here's the console results.

page load
load count(20), index (1), append(undefined), prepend(undefined) : 20 loaded first time - perfect
load count(20), index (-19), append(undefined), prepend(id:179) : 0 loaded - perfect
user scrolls down 20 
load count(20), index (21), append(id:43), prepend(undefined) - next 20 perfect
load count(20), index (-3), append(undefined), prepend(id:97) : 16 loaded - problem (a) 
load count(20), index (19), append(id:96), prepend(undefined) : 20 loaded - problem (b)
load count(20), index (-4), append(undefined), prepend(id:104) : 15 loaded - problem (a/b)
.
.

...and so on... I hope you can find that I'm doing something wrong. A few questions.

  1. Is there a demo using get descriptor prepend/append?
  2. I am loading an object array as reference, I assume this is okay, I don't have to push a copy of the array values right?

Here is the code I used to do cursor scrolling of results - it seems like the right approach, just not sure why this version of get is calling me in this fashion.

 var feedsource;
    feedsource = {};
    feedsource.get = function (descriptor, success) {
        var max_id, since_id;
        if (descriptor.append) {
            max_id = descriptor.append.aId;
        }
        if (descriptor.prepend) {
            since_id = descriptor.prepend.aId;
        }
        console.log('load count(' + descriptor.count + '), index (' + descriptor.index + '), append(' + max_id + '), prepend(' + since_id + ') ');
        loadFeedCursor(descriptor.count, max_id, since_id).then(function (resp) {
            console.log(':' + resp.items.length);
            return success(resp.items);   // array of my json objects - assuming this is okay
        });
    };



        <div ui-scroll-viewport fill-height>
            <ul class="list-group list-group-sm no-radius m-b-none m-t-n-xxs">
                <li ui-scroll="post in feedsource" buffer-size="20" class="list-group-item clearfix b-l-3x" adapter="feedAdapter.adapter">
                    <div ng-include="'tpl/feed.detail.post.html'"></div>
                </li>
            </ul>
        </div>
Marty

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions