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

endless-react

v1.0.0

Published

An infinite scroll React component

Downloads

5

Readme

endless

A bi-directional infinite scroll React component.

Installation

The best way is to use bower.

bower install endless

Alternately, you may copy and include the file endless.js to your project. Make sure you check for updates occasionally.

API

Setup

$(container).endless(options);

The options object must at least contain a getItem callback.

The container must be scrollable, and may contain the following children, identified by class name. Class names may be hyphenated or camelCase. All of these are optional.

  • endless-above: a (preferably) empty div used as a spacing element. Should have a background image or animation indicating that items are loading. It may be resized.
  • endless-items: a container for items. It may contain a template for a single item — if this is provided, getItem will always get an item to recycle. The template will be removed from the DOM during setup.
  • endless-empty: content to display when it’s known that there are no items.
  • endless-loading: content to display while waiting for the first item.
  • endless-below: The antipodal counterpart of endless-above.

Options

  • getItem, mandatory, a function that is invoked when a new item needs to be rendered. It will receive three arguments: index, an integer which may be positive or negative, template, a DOM element that may be reused, and an optional callback. The function may return a rendered item, false to indicate that the end of the list has been crossed, or true to indicate that the item needs to be loaded asynchronously. In the final case, the callback must be invoked with one argument: the rendered item or false if the list has ended.
  • columns, a positive integer. When greater than 1, items are displayed in a masonry-like grid.
  • ramp, the number of pixels above and below the viewport that should be filled with items so that users don’t see loading indications while scrolling slowly.
  • onScroll, a function that is invoked when the scroll position changes. It will receive one argument, position which may be an integer, -Infinity (top) or +Infinity (bottom). Important: Use this instead of attaching handlers to the container element’s scroll event; such handlers will be fired incorrectly when endless adds or removes elements, and may severly degrade performance due to layout thrashing.

Methods

These methods only work if .endless() has been called on the container previously.

  • $(container).scrollPos() returns the current position: an integer index or ±Infinity
  • $(container).isInTree(index) checks whether the item at a particular index is in the DOM.
  • $(container).isInView(index) checks whether the item at a particular index is in view.
  • $(container).scrollTo(position) scrolls to the given position.
  • $(container).reset(position) Indicates that all the DOM elements need to be refreshed by calling getItem — this is usually done if all the items have changed (e.g. because a new data set has been selected).
  • $(container).update(index, changed) tells endless that a particular item is to be updated. changed (boolean, default false) may be used to indicate that the application has already updated the item in the DOM, and endless should only reposition other items.
  • $(container).insert(index) tells endless that a new item is to be inserted at the given position. Subsequent indexes are assumed to be incremented by 1.
  • $(container).delete(index) tells endless that the item at the given position is to be deleted. Subsequent indexes are assumed decremented by 1.

Notes

Each element is identified by its integer index, which can be negative, zero or positive. The first call to getItem during setup will get the index 0.

The scroll position of the list may be the index of the first visible item, -Infinity (top) or +Infinity (bottom).