npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-vscroll

v0.9.0

Published

virtual scrolling for web collections

Downloads

4

Readme

#vscroll + angularjs Angular virtual scroll that can be applied to any ng-repeat markup.

vscroll can offer performance benefits when working with very large collections. It does so by only rendering and processing a subset of the data which is visible to the user vs. processing the entire list of data. By creating only DOM elements for the visible items, this can greatly reduce the amount of work it has to do. ##Licence Code licensed under MIT license.

Examples

http://klumba12.github.io/vscroll/ ##Installing via Bower bower install vscroll

Get Started

###Module Don't forget to include vscroll module!

anuglar.module('some-module-name', ['vscroll',...])

###Controller Inject scroll service to controller and invoke it to create vscroll context.

var app = angular.module('app', ['vscroll']);
app.controller('vscrollTest', ['$scope', 'vscroll', function ($scope, vscroll) {
    $scope.data = [];
    for (var i = 0; i < 200; i++) {
	    $scope.data[i] = 'item ' + i;
    }

    $scope.vscrollContext = vscroll({threshold: 30});
}

###API vscroll service returns instance that connects user settings, scroll port and scroll filter. User should inject service to angular controller and invoke it by passing settings object

vscroll({
	/**
 	* The number defines how many items will be materialized to dom elements.
 	* @default 64.
 	*/
	threshold: 30,

	/**
	 * The function defines method of getting data for next page of infinite scroll.		
	 * @param {number} skip How many elements should by skipped to get next page.
	 * @param {number} take Size of next page.
	 * @param {deffered} deferred Deffered object that should be resolved with total number of items.
	 * @default angular.noop
	 */
	fetch: function (skip, take, d) {
        getSomeData(skip, take)
          	.success(function(data){
               	$scope.data = data;
               	// if you don't know total number of items
               	// you can use "+ take" expression,
               	// it says that next page can be fetched
               	d.resolve(data.length + take);
            });
        }		
})

###HTML markup

  • Add vscroll directive to element with scroll bars
  • Add vscroll-port directive to scrollable element
  • Add vscroll filter and track by $index into ng-repeat directive
  • Add vscroll-row or vscroll-column to the repeated element that will be virtualized
  • Bind vscroll context to the vscroll-port directive and vscroll filter
  • Bind once $index to the vscroll-row or vscroll-column directive
<div ng-controller="vscrollTest" vscroll>
        <ul vscroll-port="vscrollContext">
            <li vscroll-row="{{::$index}}" 
            	ng-repeat="item in data | vscroll: vscrollContext track by $index">
               {{$item}}
            </li>            
        </ul>
    </div>

Development

To setup development environment make sure that npm is installed on your machine, after that just execute npm command for the project.
npm install ##Testing We use phantomjs and jasmine to ensure quality of the code. The easiest way to run these asserts is to use npm command for the project.
npm test ##How it works We believe, that core concept of vscroll is simplicity. We don't implement complex transclusions or our own ng-repeat directive, we just use angular's native tools. We don't change elements, we change collection, and angular is responsible for the rest.

vscroll filter returns to ng-repeat expression ~threshold number of elements. We force to use track by $index expression to make angular think that collection is constant and there is no need to recreate dom elements.

vscroll core principles:

  • To store list of element offsets from the top/left container side.
  • To understand which elements should be displayed(thanks to binary search in offsets).
  • To calculate lower and upper indexes for collection(return to ng-repeat window of elements).
  • To add paddings to top/bottom or left/right container sides(emulate vertically/horizontally scroll).

Angular Compatibility

To get maximum performance benefits from vscroll, anuglar 1.3+ should be used, regarding to one-time binding support,

<div vscroll-row="{{::$index}}"/>