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

reassemble

v0.5.6

Published

Fast Library for the Composition of React Higher-Order-Components

Downloads

4,851

Readme

reassemble

reassemble is a library for the composition of React Higher-Order-Components optimized for performance.

NPM Version Widget Build Status Widget Coverage Widget

reassemble vs recompose

reassemble is very similar to recompose. Conceptually both projects differ in such way that recompose uses HOCs as their building blocks, whereas reassemble uses Composables which are just a collection of callbacks. Most noticeably using reassemble only results in a single Higher-Order-Component and thus has a significant higher performance. It also solves the problem of Dev Tools Ballooning which is an issue in recompose.

Using recompose together with reassemble

Both projects are not mutual exclusive but reassemble can be used perfectly together with recompose. In the end reassemble just produces a Higher-Order-Component that fits in nicely with the composition tools of recompose.

Performance

At the moment recompose is a bit faster in simple compositions (though we plan to close this gap) and reassemble performs better in complex composition.

Check out current benchmarks

Installation

npm install reassemble --save

Usage

import { assemble, withState, mapProps } from "reassemble"

const enhance = assemble(
  withState(/*...args*/),
  mapProps(/*...args*/),
);
const EnhancedComponent = enhance(BaseComponent);

Note: assemble is also exported with the alias compose to allow easy transition from recompose to reassemble

Size optimization

reassemble exports also as ES6 modules and as such tree shaking (e.g. with webpack 2) can be used to effectively reduce file size.

Without tree shaking you can import the modules explicitly:

import mapProps from "reassemble/lib/mapProps"
import withState from "reassemble/lib/withState"

And for ES5 projects:

const mapProps = require("reassemble/cjs/mapProps").mapProps
const withState = require("reassemble/cjs/withState").withState

Combining

Multiple Composables can be combined into one using combine() which makes it easy to define your own:

export const withClickCounter = combine(
  withState('counter', 'setCounter', 0),
  withHandlers({
    onClick: ({counter, setCounter}) => setCounter(counter + 1),
  }),
);

This is also useful for some Composables like branch that takes another Composable as an argument.

Support for Symbols

Most of the Composables supports the use of ES6 Symbols. You can use Symbols to pass hidden props among your Composables.

* In some cases TypeScript users will lose type information.

Note for TypeScript users

reassemble is written in TypeScript and as such comes with its own definitions. They do not follow the same type definitions as recompose so some manual work is required here.

Support of recompose HOCs as Composables

| Name | Support | Remarks | | ----------------------------------------------------- | :-----: | ------- | | branch | ✅ || | defaultProps | ✅ || | flattenProps | ✅ || | getContext | ✅ || | lifecycle | ❌ | Use Lifecycle Composables | | mapProps | ✅ || | mapPropsStream | ❌ | File an issue if you really need this | | onlyUpdateForKeys | ✅ || | onlyUpdateForPropTypes | ❌ | Use onlyUpdateForKeys instead | | renameProp | ✅ || | renameProps | ✅ || | renderComponent | ✅ || | renderNothing | ✅ || | setDisplayName | ✅ || | setPropTypes | ✅ || | setStatic | ✅ || | shouldUpdate | ✅ || | pure | ✅ || | withContext | ✅ | Context will not be available in other Composables of the same Component | | withHandlers | ✅ || | withProps | ✅ || | withPropsOnChange | ✅ || | withReducer | ✅ || | withState | ✅ || | toClass | ✅ ||

Composables introduced by reassemble

debug()

debug(callback: (props) => void): Composable

Runs callback with current props. Defaults to logging to the console.

noOp

noOp: Composable

omitProps()

omitProps(...keys: string[]): Composable

Omit selected props.

isolate()

isolate(...composables: Composable[]): Composable

Runs passed Composables in isolation: any props created will be reverted. Use with integrate() to selectively keep props.

isolate(
  withProps({
    a: 1,
    b: 2,
  }),
  integrate("b"),
)
// { b: 3 }

integrate()

integrate(...keys: string[]): Composable

Selectively keep props that are otherwise reverted in isolate().

Lifecycle

onWillMount()

onWillMount(props): Composable

Called during lifecycle componentWillMount()

onDidMount()

onDidMount(props): Composable

Called during lifecycle componentDidMount()

onWillUnmount()

onWillUnmount(props): Composable

Called during lifecycle componentWillUnmount()

onWillReceiveProps()

onWillReceiveProps(prevProps, nextProps): Composable

Called during lifecycle componentWillReceiveProps() and when state changes because some props are derived from state.

onWillUpdate()

onWillUpdate(prevProps, nextProps): Composable

Called during lifecycle componentWillUpdate()

onDidUpdate()

onDidUpdate(prevProps, nextProps): Composable

Called during lifecycle componentDidUpdate()

Roadmap

  • More performance optimizations
  • More tests

License

MIT