Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

incompose

zanettin145MIT5.0.1

An inferno utility belt for function components and higher-order components

inferno, recompose, functional, component, higher, order, component, hoc

readme

Inferno JS Logo

Incompose

Incompose is a Inferno.js clone of the famous recompose lib for React.

Build Status npm version npm downloads Code Climate Test Coverage MIT

Installation

npm install incompose

Incompose / Inferno version map

Incompose works with specific version of inferno. Please make sure you use the correct version.

Inferno verion Incompose version
v7.x >= v.5.0.0
v6.x >= v.4.0.0
v5.x >= v.3.0.0
v4.x v.2.0.0
< v4.0 < v.2

Support

Following HoCs are available. If you miss any helper/HoC please send me a note on twitter @roman_zanettin or create an issue / open a PR. Thanks.

Function since
branch 0.0.8
componentFromStream 1.1.0
compose 0.0.3
createEventHandler 1.1.0
createSink 0.0.6
defaultProps 0.0.3
flattenProps 0.0.4
mapProps 3.0.1
nest 0.0.7
pure 0.0.8
renderComponent 0.0.8
renderNothing 0.0.5
renameProp 0.0.4
renameProps 0.0.4
setObservableConfig 1.1.0
shouldUpdate 0.0.3
withHandlers 0.0.5
withLifecycle 0.0.3
withProps 0.0.3
withPropsOnChange 0.0.6
withReducer 0.0.7
withState 0.0.3

Usage

Please find the API and example code in the docs folder.

Import

Incompose provides named and default imports:

import {withState} from 'incompose';
import withState from 'incompose/dist/withState';

Example

import {
  linkEvent
} from 'inferno';

import {
  compose,
  withState,
  shouldUpdate
} from 'incompose';

const inc = (props) => {
  props.setCount(props.count += 1);
};

const dec = (props) => {
  props.setCount(props.count -= 1);
};

const Counter = (props) => (
  <div>
    <h1>count : {props.count}</h1>
    <button onClick={linkEvent(props, dec)}>-</button>
    <button onClick={linkEvent(props, inc)}>+</button>
  </div>
);

/**
 * with state creates 2 new props on the component props
 * props.count        -    contains the value (1 is set as default value)
 * props.setCount    -    contains the setter function
 */
const withCounterState = withState('count', 'setCount', 1);

/**
 * should update prevents the component of re-render (shouldUpdate lifecycle hook)
 * you can compare current and next props and decide whether the component
 * should update or not. In this example, the counter just updates if
 * props.count is even.
 */
const withUpdatePolicy = shouldUpdate((props, nextProps) => (
  nextProps.count % 2 === 0
));

/**
 * with compose all the extended functions are composed BEFORE Counter
 * gets rendered. Please not that order matters.
 */
export default compose(
  withCounterState,
  withUpdatePolicy,
)(Counter);

Thanks

Special thanks to all the contributors and Andrew Clark (@acdlite) for creating this amazing lib for React!

Changelog

Changelog is available here.

changelog

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[5.0.1] - 2019-07-06

Update

  • shouldUpdate and withLifecycle use inferno hooks under the hood

    Fixed

  • fixed issue #26 composition issues - thx to ioi0!

[5.0.0] - 2019-06-27

Update

  • upgraded all npm packages
  • inferno v7 support

Fixed

  • withState is composable again - thx to ioi0!

[4.0.0] - 2018-11-18

Update

  • upgraded all npm packages
  • babel v7 support
  • inferno v6 support

[3.0.2] - 2018-10-19

Fixed

  • added named import for mapProps

[3.0.1] - 2018-10-19

Added

  • mapProps - thx to ZoltanDalmadi

[3.0.0] - 2018-03-18

Update

  • incompose is now ready for inferno ^5.0 - thx to IgnusG!

[2.0.0] - 2018-02-11

Update

  • incompose is now ready for inferno ^4.0
  • updated all dependencies
  • removed inferno-compat as dependency
  • added inferno-create-class as dependency
  • use node 9.5.0 internally

[1.1.0] - 2017-08-07

Added

  • componentFromStream
  • createEventHandler
  • setObservableConfig
  • observable configs for bacon, flyd, kefir, most, rxjs4, rxjs, xstream

Update

  • updated npm dependencies

[1.0.0] - 2017-07-29

Update

  • updated npm dependencies
  • updated docs
  • moved to first stable version

[0.0.15] - 2017-05-2

Update

  • updated npm dependencies and fixes - thx to @FQ400!
  • updated docs

[0.0.14] - 2017-04-12

Fixed

  • fixed isClassComponent - thx to @FQ400!
  • spelling fixes - thx to @FQ400!

[0.0.13] - 2017-04-11

Update

  • updated npm dependencies and fixes - thx to @FQ400!

[0.0.12] - 2017-04-06

Update

  • updated npm dependencies

[0.0.11] - 2017-02-23

Fixed

  • issue #2 (inferno-devtools crashes because of withLifecycle)

Breaking changes

  • lifecycle hooks have to be named like class lifecycle hooks and no longer like the functional component lifecycle hooks. from: onComponentDidMount to: componentDidMount.

[0.0.10] - 2017-02-17

Fixed

  • update dependencies

[0.0.9] - 2017-02-15

Fixed

  • update dependencies

[0.0.8] - 2017-02-15

Added

  • pure
  • branch
  • renderComponent

[0.0.7] - 2017-02-12

Added

  • nest
  • withReducer

[0.0.6] - 2017-02-10

Added

  • Documentation
  • createSink

Fixed

  • isClassComponent check

[0.0.5] - 2017-02-07

Added

  • Changelog.md
  • renderNothing
  • withHandlers

Fixed

  • added named imports for renameProp, renameProps, flattenProps

[0.0.4] - 2017-02-06

Added

  • renameProp
  • renameProps
  • flattenProps

[0.0.3] - 2017-02-04

Added

  • compose
  • defaultProps
  • withLifecycle
  • withProps
  • withState