orwell
orwell
is a higher-order component that can listen to Probe cursors for changes, and re-renders the wrapped component whenever any cursor emits a change.
Usage
$ npm install --save orwell
const OrwellWrapped = ; // static methods // set custom shouldComponentUpdate(nextProps, nextState).// returns same wrapped componentconst OrwellWrapped2 = OrwellWrapped; // sets shouldComponentUpdate(nextProps, nextState) to perform shallow equal on props. // any two Probe cursors it compares are compared as currentProbe.deref() === nextProbe.deref()// returns same wrapped componentconst OrwellWrapped3 = OrwellWrapped; // sets shouldComponentUpdate(nextProps, nextState) to perform deep equal on props.// any two Probe cursors it compares are compared as currentProbe.deref() === nextProbe.deref()// returns same wrapped componentconst OrwellWrapped4 = OrwellWrapped; // inject object to be merged with component spec of the OrwellWrapped component// returns newly wrapped componentconst OrwellWrapped4 = OrwellWrapped; // enable debug mode// returns same wrapped componentconst OrwellWrapped5 = OrwellWrapped;const OrwellWrapped6 = OrwellWrapped; // enableconst OrwellWrapped7 = OrwellWrapped; // disable
shouldComponentUpdate
By default, orwell
uses a shouldComponentUpdate()
that is equivalent to React's PureRenderMixin
, but compares Probe different by doing something like:
!currentProbe === nextProbe
The props passed to shouldComponentUpdate(nextProps, nextState)
is equivalent to Object.assign({}, props, assignNewProps(props, context))
.
Inspiration
orwell
has been inspired by connectToStores
code written by @gaearon in his article promoting usage of Higher-order components: https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750
License
MIT