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

react-flyd-component

v2.2.1

Published

Live-Updating Stateless React Components Using Flyd

Downloads

11

Readme

React Flyd Component

Build Status GitHub issues Dependencies

Live-Updating, "Stateless" React Components Using flyd

👏 TMTOWTDI

This allows you to easily utilize flyd streams in react components without absorbing the streams, and updates the component according to changes therein.

This is how I personally prefer to work with streams. If you'd like to do things differently, there are other solutions out there such as Lift. 😀

Technically...

A streaming component that will automatically update and reconcile the DOM based on updates to streams passed to it via props, or added via setStreams.

This is better utilized at a lower level (i.e. with form inputs), so that higher level components with many streams don't refresh frivilously. (But hey - do what you want.)

This component intentionally will not copy the data to state, in order to avoid potentially stale data, memory bloat, and to give the render function full access to the raw stream (rather than just the data). This makes it easier to 'react' :)

Hey wait a second...

If you dig in, you will see that this component uses forceUpdate gasp. It's common practice to avoid this component method, and often the use of it is an immediate code-smell, but this is precisely why is exists - the streams know more about the underlying data than React does, so when they change then React should respond.

Examples

Basic Usage:

// import
import Flyd from 'react-flyd-component';

// write some helpers
function bindValue(cb) {
  return e => cb(e.target.value);
}

// wrap an ordinary component
const EmailField = Flyd((props) => {
  // this is kind of a bad example because it's not really
  // possible to tell which prop is a stream just by reading
  // this render function, but that's always the challenge,
  // isn't it? 😬

  // I'll leave it to the reader to determine an appropriate
  // naming convention for the streams passed via props.
  return (
    {/* use streams for content */}
    <label htmlFor="props.name">{props.label()}</label>
    <input
      type="email"
      {/* mix streams and normal values freely */}
      name={props.name}
      {/* get your stream's value by calling it */}
      value={props.value()}
      {/* or access it by reference to pass it elsewhere */}
      onChange={bindValue(props.value)}
    />
});
// render/export or something down here

Advanced Usage:

// import
import { stream } from 'flyd';
import { StreamingComponent } from 'react-flyd-component';

// create a massively complex multi-stream component
// (if that's what you're into)
class InsaneComponent extends StreamingComponent {
  constructor(props) {
    super(props);

    // you might not *want* to store streams on state,
    // but there's nothing stopping you from doing it!
    this.state = {
      message: stream(),
      input: stream(),
      something: stream(),
    }

    // state is not automatically evaluated.
    // add an array of streams to watch manually
    this.setStreams([
      this.state.message,
      this.state.input,
      this.state.something,
    ]);

    // that's it.  this component will now update
    // automatically with every stream change.
  }
  // needs a render function obvs
}
// render/export

Advanced Usage Note:

This HOC hooks into both the componentWillMount, componentDidMount, and componentWillUnmount lifecycles, so if you choose to use those lifecycles as well you should call the super of those methods (e.g. super.componentWillMount()) at runtime as well.