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

react-generational-purify

v1.0.0

Published

Purify Function for React for Generational Caching

Downloads

2

Readme

#React Generational Purify

A version of React's PureRenderMixin for functional components.

For more motivation, check out the React Advanced Performance Docs.

Usage

npm install react-generational-purify --save
const purify = require('react-generational-purify');

const PureFunComp = purify(props => <div>{props.foo}</div>);

The PureFunComp component will now skip rendering if the props and context have not changed.

Why Generational

Functional components are difficult to memoize because they do not have a this and you cannot tell the difference between different instances of the same component. An implementation of purify is to remember the props and context for the last render of each functional component. Then on the next render, you can skip rendering if the props and context have not changed. This implementation is limited if you have components with more than one instance on the page, e.g.:

const purify = require('react-generational-purify');
const Item = purify(props => <li>{props.position}</li>);
<ul>
  <Item position="first" key=0/>
  <Item position="second" key=1/>
</ul>

If different instances receive different props, the render method will never be skipped.

Another implementation of purify is to remember all combinations of props and context passed into render. This does skip rendering efficiently, but uses a lot of memory and can eventually crash the browser in many applications.

In the generational implementation, we keep track of all combinations of props and context that have been passed into render in the last generation. A generation is defined as a group of synchronous render calls. In the flux pattern, it is common to always re-render the top level component in your application. This will then synchronously render all children of the application, which eventually re-renders all instances of all components on the screen.

In the above example, if you render the ul, rendering Item with {position: "first"} and rendering Item with {position: "second"} will both be tracked. When you re-render the ul, it will know about both previous renders of Item and skip rendering on them. This will be true no matter how many times you render ul.

The net effect is that in each top-level render of your application, only the instances of components that have changed since the last top-level render will be rendered.