Coder Social home page Coder Social logo

Comments (11)

kamilkp avatar kamilkp commented on June 9, 2024

I use infinite scrolling behaviour with vs-repeat. I just load more content when the user scrolls to the bottom and append those elements to the source array. But if you wanted the scroll to mimic like the entire collection of items is there then the vs-repeat fill element would have to have a proper size. I'd go with providing that size to vs-repeat rather then create fake items in the array. You're welcome to create a pull request on that if you are willing to implement this. And if you do remember that vs-repeat has a mode when you provide it with vs-size-property attribute. It also has to be taken into account.

from angular-vs-repeat.

kentcdodds avatar kentcdodds commented on June 9, 2024

Question about infinite scrolling you've done... How did you accomplish that with vs-repeat? I'm trying to use ngInfiniteScroll but that's not working for me because the way that it works and the way that vs-repeat work. Is there any way that I could pass vs-repeat a function to call when the user is x items away from the bottom? Would you accept a PR that would do this?

from angular-vs-repeat.

kamilkp avatar kamilkp commented on June 9, 2024

Hmm, looks to me that this could be accomplished fairly easy without modifying the library. My virtual scroll was fetching more elements when the user scrolled all the way down. So i set up an event listener for the scroll event and in thr handler i check the scroll position. If you want the fetching to be triggered when the user is 'x' items away you could set up a '$watch' on a proper scope and watch for 'startIndex' or 'endIndex' vs-repeat inner property. Then check if 'collectionLength - endIndex < x' fetch more elements.

from angular-vs-repeat.

kentcdodds avatar kentcdodds commented on June 9, 2024

Cool. Seems like that would work pretty well. I'm having internet issues right now preventing me from trying it out on jsbin, but I'll give it a shot. Looks promising though. Would probably be something to add to the docs as an example for sure.

from angular-vs-repeat.

kentcdodds avatar kentcdodds commented on June 9, 2024

Looks like this doesn't work with the current implementation. The problem is that vs-repeat creates a child scope and I don't have access to the endIndex that's created by the vs-repeat's scope. We need to add that as an additional attribute to bind that properly. I'll make a PR for this and we'll see what you think.

from angular-vs-repeat.

kamilkp avatar kamilkp commented on June 9, 2024

Hmm,
you said that:

vs-repeat creates a child scope and I don't have access to the endIndex that's created by the vs-repeat's scope

As it's true that vs-repeat created a scope, it is not true that you don't have access to it. At first i thought about accessing it via $$childHead property on the parent scope, but that obviously is far from an elegant solution. But there is one very elegant. I have created a fiddle for you to check out how it's done: http://jsfiddle.net/tcv2oz41/1/

Basically the idea is to use ng-init directive on the vs-repeat element like this:

ng-init="setUpWatcher()"

and then in your controller write a function like this:

$scope.setUpWatcher = function(){
    // this - is a reference to the scope that originally calls
    // this method i.e. the vs-repeat scope
    this.$watch('endIndex', function(val){
        $scope.currentEndIndex = val;
    });
};

from angular-vs-repeat.

kentcdodds avatar kentcdodds commented on June 9, 2024

That's a very interesting approach.... I believe it is acceptable. Though I
believe that my PR is a more elegant and straightforward solution. Is there
a reason you would prefer to avoid merging my PR?

Kent C. Dodds
https://twitter.com/kentcdodds
https://plus.google.com/114245123507194646768 [email protected]
http://www.linkedin.com/profile/view?id=67772537
http://mormon.org/me/1J5N/Kent

On Wed, Sep 10, 2014 at 12:31 AM, kamilkp [email protected] wrote:

Hmm,
you said that:

vs-repeat creates a child scope and I don't have access to the endIndex
that's created by the vs-repeat's scope

As it's true that vs-repeat created a scope, it is not true that you
don't have access to it. At first i thought about accessing it via
$$childHead property on the parent scope, but that obviously is far from
an elegant solution. But there is one very elegant. I have created a fiddle
for you to check out how it's done: http://jsfiddle.net/tcv2oz41/1/

Basically the idea is to use ng-init directive on the vs-repeat element
like this:

ng-init="setUpWatcher()"

and then in your controller write a function like this:

$scope.setUpWatcher = function(){
// this - is a reference to the scope that originally calls
// this method i.e. the vs-repeat scope
this.$watch('endIndex', function(val){
$scope.currentEndIndex = val;
});};


Reply to this email directly or view it on GitHub
#10 (comment)
.

from angular-vs-repeat.

kamilkp avatar kamilkp commented on June 9, 2024

Well the library shall be kept simple. If something can be implemented in a clean way without the need to extend the library that's what i prefer. Otherwise all those little extensions will eventually take their toll on performance for user that don't use nor need those features. And by the way, you set up a $watch there which is not needed because startIndex and endIndex is basically changed only in one place in code so this function could be called directly from there. Also the $parse($attrs.vsOnIndexChange) in every watcher handler is inefficient. This expression could be parsed once and then the result of parsing (a function) called on $scope in the handler.

from angular-vs-repeat.

kentcdodds avatar kentcdodds commented on June 9, 2024

All terrifically valid points. Thanks for the help!

from angular-vs-repeat.

kamilkp avatar kamilkp commented on June 9, 2024

One more thing. You can write a reusable directive like this:

directive('onVsIndexChange', ['$parse', function($parse){
    return function($scope, $element, $attrs){
        var expr = $parse($attrs.onVsIndexChange);
        var fn = function(){
            expr($scope);
        }
        $scope.$watch('startIndex', fn);
        $scope.$watch('endIndex', fn);  
    };
}]);

and use it like that:

<div vs-repeat on-vs-index-change="indexChanged(startIndex)">
    <!-- ... -->
</div>

That way you are not extending the library but at the same time you have basically the exact same api as the one that you prefer.

from angular-vs-repeat.

kentcdodds avatar kentcdodds commented on June 9, 2024

I have learned a few very useful techniques from you here! Thanks!

from angular-vs-repeat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.