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

polyrhythm-react

v1.9.2

Published

[![npm version](https://badge.fury.io/js/polyrhythm-react.svg)](https://badge.fury.io/js/polyrhythm-react) [![Travis](https://img.shields.io/travis/deanius/polyrhythm-react.svg)](https://travis-ci.org/deanius/polyrhythm-react)

Downloads

314

Readme

npm version Travis

polyrhythm-react 🎵🎶

polyrhythm-react gives you ways to use polyrhythm in a React context.

polyrhythm is a Domain Specific Language for building UIs with JavaScript. See the polyrhythm README

It's a synthesis of ideas from:

  • 💙JQuery, particularly #on and #trigger.
  • 💜RxJS. Older than Promises, nearly as old as JQuery.
  • 💜Redux-Observable, Redux Saga, Redux Thunk.

and can functionally replace parts or all of these in your app, adding under 8Kb to your bundle size.

Installation

npm install polyrhythm-react

Responding to events

useFilter and useListener are React wrappers over the polyrhythm exported functions filter and listen. What these hooks do is scope the lifetime of the event listener, and its side-effects, to the lifetime of the component. This has the benefit that effects will not accidentally linger beyond the lifetime of the component (and you can "lift" their listeners to a higher component in the tree if you want those effects to continue.)

deps, may be passed, so as not to close over stale values - however, a best practice is not to read state in the event listener, but in the triggerer, and pass that along in the event.

TODO: Examples

Mount-time Hooks

useEffectAtMount - there should be a lint rule to insist that calls to useEffect(fn, []) get rewritten to the more self-explanatory "use effect at mount". Its purpose is to scope the lifetime of a cancelable effect to that of its component.

useEffectAfterMount allows you to skip running the effect upon component's first render. Perfect for when you mean to specify an effect to run only upon changes of a certain value, with cancelation, but not at mount time. Example useEffectAfterMount(sendToAnalytics, [clickCount]).

Multiple Channel support

useChannel is available for more advanced scenarios where a different channel is desired, such as for keeping one sub-tree's events separated from the default, for privacy, simulating a server in-browser (!), or other reasons.

Declarative Concurrency

ASAP (mergeMap, default)

Queued (concatMap)

Restarting (switchMap)

Throttled (exhaustMap)

Automatic Cancelation

Middleware

Adding triggerAllMiddleware(channel) to your Redux middleware stack will automatically trigger a polyrhythm event-channel event for every Redux action.

Use this to open a debugger (or console.log) when any Redux event happens.

import { channel, triggerAllMiddleware } from 'polyrhythm-react';

middlewares = [
  ...
  triggerAllMiddleware(channel)
]

channel.filter('interesting/event', event => {
  console.log('Found an interesting event', event);
  debugger // View the Call Stack to find the action dispatcher!
})

For More Information

See the benefits and learn more in the polyrhythm README.