Giter Site home page Giter Site logo

cartant / recompose-etc Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 343 KB

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

Home Page: https://cartant.github.io/recompose-etc/

License: MIT License

JavaScript 5.37% TypeScript 94.63%
react recompose rxjs

recompose-etc's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.