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

@cascadium/pologram

v0.1.18

Published

A React component for scolling over huge list with windowing technique

Downloads

21

Readme

pologram

A React component for scolling over huge list with windowing technique

NPM JavaScript Style Guide

Install

With npm:

npm install --save @cascadium/pologram

Or with yarn:

yarn add @cascadium/pologram

Usage


// You need to import some predefined styles first. Of course
// you may override it by adding inline styles.
import '@cascadium/pologram/dist/index.modern.css';

// ...

const pologram = <Pologram {...{
  itemData,
  rowRenderer, 
  topWidgetRenderer,
  height,
  buffer,
}} />

where:

  • itemData: the list of data to be rendered
  • rowRenderer: the React component that renders the row.
  • topWidgetRenderer: the React component that renders a widget sticky to the top of the list.
  • height: height of the view, must be specified
  • buffer: the number of rows to be rendered ahead of visible ones, so that to prevent rendering AFTER moving into visible area (which makes the table looking 'flashy' when scrolling fast).

the rowRenderer and topWidgetRenderer will be explained in the following sections.

The Row Renderer

Since Pologram is derived from a personal project, it doesn't have strict type check, an will not look into the implementation of row renderer, however improper row renderer will cause unexpected behavior. Here is an example of row renderer implementation. You may also find it in the example of source code.

forwardRef(({index, data, style}, ref) => {

  const outerStyle = {
    width:'100%',
    ...style
  }

  const innerStyle = {
    width: '100%',
    display:'flex',
    alignItems: 'center',
  }

  return <div style={outerStyle}>
    <div style={innerStyle} ref={ref}>
      <InnerElem {...data[index]}/>
    </div>
  </div>
});
  1. The row renderer is wrapped by a component that measures the rendered DOM (called Measurer if you look into the code). It needs the ref of the inner div element. Thus the row renderer must pass the ref out. If your row render is a functional component, then it should be wrapped with forwardRef.

  2. The height of the element with innerStyle will be measured, which determines the position of rows to be rendered. The inner style doesn't have to be inline style, it can also be specified via CSS.

  3. The calculated position of the row will be assigned back to the element with the style property, and finally assigned to the row via outerStyle. The style contains four CSS property, which are top, bottom and height. You may add other CSS properties to the inline style, or refer some style with className, but always remember to use the style passed into, and never mess it up. Otherwise the rows will not show properly, or never render at all.

  4. The data is the whole list. The record data to be rendered can be referenced by index of the data. We use this instead of merely passing the record ( the content of data[index]) is that you may need to interact with other rows in the current row. Moreover, when you pass an object into a React component as prop, React will make it immutable by Object.freeze it. Passing the whole data table avoids the single record being frozen.

(Personally I don't accept the idea of making everything immutable. The data table could be huge or could contain complex shape, returning a new object for each operation is counterintuitive and excessively costy)

License

WTFPL marvintau