Skip to content
vic

zanettin/incompose

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

zanettin/incompose.json
{
"createdAt": "2017-02-04T16:08:09Z",
"defaultBranch": "master",
"description": "A inferno utility belt for function components and higher-order components",
"fullName": "zanettin/incompose",
"homepage": null,
"language": "JavaScript",
"name": "incompose",
"pushedAt": "2019-07-06T14:25:01Z",
"stargazersCount": 79,
"topics": [
"functional-components",
"functional-programming",
"higher-order-component",
"hoc",
"inferno",
"inferno-js",
"javascript",
"npm",
"npm-package",
"recompose"
],
"updatedAt": "2024-11-30T05:48:52Z",
"url": "https://github.com/zanettin/incompose"
}

Inferno JS Logo

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

Build Status npm version npm downloads Code Climate Test Coverage [MIT]!(LICENSE.md)

npm install incompose

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

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

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.

Functionsince
[branch]!(docs/branch.md)0.0.8
[componentFromStream]!(docs/componentFromStream.md)1.1.0
[compose]!(docs/compose.md)0.0.3
[createEventHandler]!(docs/createEventHandler.md)1.1.0
[createSink]!(docs/createSink.md)0.0.6
[defaultProps]!(docs/defaultProps.md)0.0.3
[flattenProps]!(docs/flattenProps.md)0.0.4
[mapProps]!(docs/mapProps.md)3.0.1
[nest]!(docs/nest.md)0.0.7
[pure]!(docs/pure.md)0.0.8
[renderComponent]!(docs/renderComponent.md)0.0.8
[renderNothing]!(docs/renderNothing.md)0.0.5
[renameProp]!(docs/renameProp.md)0.0.4
[renameProps]!(docs/renameProps.md)0.0.4
[setObservableConfig]!(docs/setObservableConfig.md)1.1.0
[shouldUpdate]!(docs/shouldUpdate.md)0.0.3
[withHandlers]!(docs/withHandlers.md)0.0.5
[withLifecycle]!(docs/withLifecycle.md)0.0.3
[withProps]!(docs/withProps.md)0.0.3
[withPropsOnChange]!(docs/withPropsOnChange.md)0.0.6
[withReducer]!(docs/withReducer.md)0.0.7
[withState]!(docs/withState.md)0.0.3

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

Incompose provides named and default imports:

import {withState} from 'incompose';
import withState from 'incompose/dist/withState';
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);

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

Changelog is available [here]!(CHANGELOG.md).