googlearchive / firebase-util

An experimental toolset for Firebase
http://firebase.github.io/firebase-util
MIT License
276 stars 58 forks source link

Paginate Infinite Scroll: Load Items Initially #46

Closed realph closed 9 years ago

realph commented 9 years ago

I'm following the Firebase-util Paginate Infinite Scroll demo, and was wondering if there is a way to load an initial number of items, instead of loading 0 items to begin with.

When I click on my button, I'm loading in the next 16 items. Is there a way I can load 16 items on the initial load, and then another 16 upon clicking my button, etc etc?

My HTML and JS looks like this:

index.html

<h3>Items loaded: {{scrollItems.length}}</h3>
<button ng-click="scrollItems.scroll.next(16)">Load Next 16</button>

app.js

app.controller('ServiceListController', ['$scope', '$firebaseArray', '$scrollArray',
  function($scope, $firebaseArray, $scrollArray) {
    var servicesRef = new Firebase('https://fbutil.firebaseio.com/paginate');
    $scope.scrollItems = $scrollArray(servicesRef, 'number');
}])

app.factory('$scrollArray', ['$firebaseArray', function($firebaseArray) {
  return function(ref, field) {
    var scrollRef = new Firebase.util.Scroll(ref, field);
    var list = $firebaseArray(scrollRef);
    list.scroll = scrollRef.scroll;

    return list;
  }
}])

Here's a demo of this in action.

Any help with this is appreciated. Thanks in advance!

michaeldim commented 9 years ago

Add next to the initial scroll ref: list.scroll = scrollRef.scroll.next(10);

katowulf commented 9 years ago

Yep. Just call next().

realph commented 9 years ago

@michaeldim When I add next to the initial scroll ref, it prevents me from clicking the button and loading more items.

katowulf commented 9 years ago

@realph I say all of this with the upmost love and sincerity; I've been in your shoes many times myself and have the greatest respect for the frustration of navigating through new technologies--particularly when they aren't working as expected.

You need to be more detailed, more persistent and more thorough here. Please respect the community's time and recognize that debugging the problem is your purview. Once you've reduced it to a known error, if you are having trouble finding the solution, we would love to help.

If you're looking for techniques to debug the issue, an extremely effective one is to produce an mcve. If that doesn't resolve the problem en tránsito, post the mcve with some steps to reproduce. At that point I'm happy to help you come up with solutions.

realph commented 9 years ago

Thank you for the advice @katowulf. I'll try and explain issues better in the future and follow such best practices as to not drive the community insane.

On this particular issue, would you recommend trying to do a bit of work on my end and explain it better along with an mcve in this thread, or open a new thread completely?

Thanks once again. While it is frustrating for me, I can imagine it also being frustrating for you – so apologies for the constant hammering of posts, especially when I'm not being detailed with my explanations.

michaeldim commented 9 years ago

@realph How about this: http://plnkr.co:80/v7M0vF5ziTK9MLXxsDp3