Skip to content
This repository has been archived by the owner on Nov 3, 2018. It is now read-only.
/ recompose-etc Public archive

React function components and higher-order components based on recompose and RxJS

License

Notifications You must be signed in to change notification settings

cartant/recompose-etc

Repository files navigation

recompose-etc

GitHub License NPM version Build status dependency status devDependency Status peerDependency Status Greenkeeper badge

What is was it?

A bunch of RxJS-based React components that build on those in recompose.

An experiment that - with the introduction of React Hooks - is now redundant.

Why might you need it?

At the moment, recompose-etc is something of an experiment. It seems interesting, but I'm only just starting to use it for real-world development.

recompose provides the componentFromStream component factory and the mapPropsStream higher-order component. This package builds upon those and provides two render-prop-based component factories:

  • transformProps
  • transformEvent

transformProps applies an RxJS-based transform to the properties passed from the parent component to a child - via a render prop. The render prop can be specified as a render property, a children property or a child function. An example might look something like this:

const Component = transformProps(props$ => props$.pipe(auditTime(0, animationFrame)));
const element =
  <Component
    auditedValue={highFreqValue}
    render={({ auditedValue }) => (<span>{auditedValue}</span>)}
  />;

The specified transform could apply any structural or temporal RxJS transformation to the props. It could be as simple as an auditTime or debouceTime operator, or it could be something more complicated - like an observable that connects to the Firebase FireStore.

transformEvent applies an RxJS-based transform to an event passed from a child to a parent - via a handler function. An example might look something like this:

const Component = transformEvent(event$ => event$.pipe(
  debounceTime(1000),
  distinctUntilChanged((left, right) => left.target.value === right.target.value)
));
const element =
  <Component
    handler={handleChange}
    render={({ handler }) => (<input onChange={handler} type="text"/>)}
  />;

The package's debounceEvent, debounceProps and limitToFrameRate build upon the base component factories, incorporating some specifically-composed observables.

About

React function components and higher-order components based on recompose and RxJS

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published