npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rxjs-diagrams

v1.4.8

Published

React components for visualising RxJS observables and operators

Downloads

80

Readme

RxJS Diagrams provides React Components for interactively visualising RxJS observables and operators. It is a rewrite (and redesign) of the amazing RxMarbles. The goal is to provide simple and reusable components for quickly explaining how RxJS works.

npm install --save rxjs-diagrams

Don't forget to install its peer dependencies, react and rxjs.

Usage

One input stream

This renders an SVG showing the input values and the result. The input values are converted to an observables and then transformed to an output using the transform prop.

import 'rxjs' // This imports all observables, operators, etc
import OperatorDiagram from 'rxjs-diagrams'

// Somewhere in your components...
<OperatorDiagram
  label=".distinctUntilChanged()"
  transform={obs => obs.distinctUntilChanged()}
  emissions={[
    { x: 5, d: 1 },
    { x: 35, d: 1 },
    { x: 70, d: 3 }
  ]}
  end={80}
  completion={80}
/>

Two input streams

Having multiple input streams is as simple as passing multiple value arrays and accepting them in your transform function.

import { Observable } from 'rxjs'
import OperatorDiagram from 'rxjs-diagrams'

// Somewhere in your components...
<OperatorDiagram
  label=".combineLatest((x, y) => '' + x + y)"
  transform={(a, b) => Observable.combineLatest(a, b, (x, y) => '' + x + y)}
  emissions={[
    [
      { x: 5, d: 1 },
      { x: 35, d: 2 },
      { x: 70, d: 3 }
    ], [
      { x: 10, d: 'A' },
      { x: 45, d: 'B' },
      { x: 80, d: 'C' }
    ]
  ]}
  end={80}
  completion={80}
/>

API

Exports:

  • transformEmissions
  • EmissionsView (Docs TODO)
  • TransitionEmissionsView (Docs TODO)
  • DraggableEmissionsView (Docs TODO)
  • ChainDiagram (Docs TODO)
  • OperatorDiagram (also the default export)

Emissions, End & Completion

The common three values that describe your input are: emissions, end, and completion. This is enough for this library to generate an input observable.

Emissions are an array of objects, which have a time value x and a label d. The value x must be a number. (Example: { x: 5, d: 'A' })

Completion is the time value when your observable completes. It is a number and usually you'll want it to be larger than all x values of your emissions.

End is where the component stops to draw your observable. It basically defines how long in time the diagram is. So if your end is 20 and an emission's x is 10, then the emission will be drawn right in the center.

OperatorDiagram

Props

  • label?: string: Some text that describes your transformation.

  • transform: (...input, scheduler): A function that transforms the input observables and produces an output. It receives the input observables as the first arguments and the scheduler last. You will need the scheduler to transform the virtual observable's time. For example for delay. More information on Schedulers here

  • emissions: Emission[] | Emission[][]: Here you can pass an array of emissions (described above) or an array of an array of emissions, in case you want multiple input observables.

  • end: number: Described above.

  • completion: number: Described above.

  • width: number: The width of the resulting SVG.

  • height: number: The height of the resulting SVG component.