JSPM

  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q17582F
  • License MIT

> TODO: description

Package Exports

  • @naporin0624/react-flow
  • @naporin0624/react-flow/lib/index-cjs.js
  • @naporin0624/react-flow/lib/index-esm.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@naporin0624/react-flow) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-flow

A library that connects rxjs to React.

Observables registered with the same key are subscribed only once in total.

Image from Gyazo

Usage

import ReactDOM from "react-dom";
import { Subject, scan } from "rxjs";
import { Provider, useFlow } from "@naporin0624/react-flow";

const root = new Subject<number>();
const counter$ = root.pipe(
  scan<number, number>((acc, value) => acc + value, 0)
);
const increment = () => root.next(1);
const decrement = () => root.next(-1);

const Counter = () => {
  const counter = useFlow("counter", counter$) ?? 0;

  return (
    <div>
      <p>counter: {counter}</p>
      <div>
        <button onClick={increment}>+</button>
        <button onClick={decrement}>-</button>
      </div>
    </div>
  );
};

// The counter subscribe is called only once.
const App = () => {
  return (
    <Provider>
      <div>
        <p>counter1</p>
        <Counter />
      </div>
      <div>
        <p>counter2</p>
        <Counter />
      </div>
    </Provider>
  );
};

ReactDOM.render(<App />, document.getElementById("root"));

LICENSE

MIT