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 🙏

© 2025 – Pkg Stats / Ryan Hefner

reactuate-events

v0.1.2

Published

Synchronous React component events orchestration

Readme

npm package dependencies

Reactuate Events

Reactuate Events is an answer to maintaining complex single-component UX workflows in React that do not exactly fit into the Flux architecture as they don't belong to the global state of the application and should be rather kept inside of the component. Most common examples of that would be generic components such as complex table navigators, forms with complex validation and verification workflows.

Traditional answer to this is to use callbacks that modify the state to reflect where the user is at and what should be rendered to him. The problem with this approach is that different pieces of the workflow become disconnected. Not only it's hard to comprehend such code, it is also difficult to maintain it because of the complexity of servicing all potential scenarios.

Reactuate Events uses an experimental ES7 feature of asynchronous functions to reduce the complexity of this problem. Instead of connecting disjoint pieces, one can write a sequential event handling function.

This library's benefit comes at the expense of a somewhat reduced utility of hot code replacement (if you use it), since your asynchronous processor function won't change midway. That said, the functionality provided by such functions often implies changes to state management in the component, or change in logic, which would often require a reload anyway.

Please note that this is an extremely early prototype, bugs are very likely and the API will change.

Enabling Events

In order to enable component to use Reactuate Events, we need to compose it with enableEvents:

import { enableEvents } from 'reactuate-events'

class MyComponent extends React.Component {}

MyComponent = enableEvents(MyComponent)

Registering Events

We can enable events at any time, however, the initialization most commonly would happen in the component's constructor:

constructor() {
  super()

  this.createEvent("Click")
  this.eventProcessor()
}

Triggering Events

Calling createEvent will create two properties in your component, handleClick and waitForClick. The former one is typically to be used in your render() function:

<button onClick={() => this.handleClick()} />

Handling Events

The latter (waitForClick) is to be used in the eventProcessor function that we would define to process events as they come:

async eventProcessor() {
  while (true) {
    await this.waitForClick
    await this.setStateAndWait({clicked: true})
  }
}

In the above example, we will wait for the button to be clicked and update the state to reflect that click, indefinitely.

Of course, this is not very different from the traditional approach and adds some ceremony. The elegance of this approach reveals itself when the workflows become more complicated:

async eventProcessor() {
  while (true) {
    await this.waitForClick
    await this.setStateAndWait({clicked: true})
    const value = await this.waitForInput
    await this.setStateAndWait({clicked: false, value})
  }
}

In the above example we will wait for some data input before recognizing another button click, therefore significantly simplifying handling this workflow. And it doesn't stop there. If you use a Promise library like bluebird, you can do interesting things, like waiting for an event or a timeout:

const Timeout = Symbol("timeout")
while (true) {
  const waitForTimeout = new Promise(resolve =>
    setTimeout(() => resolve(Timeout), 2000))
  const result = await Promise.any([this.waitForClick, waitForTimeout])
  if (result === Timeout) {
  // ...

(Actually, Timeout and a generic version of waitForTimeout are also provided by this library)

It is worth mentioning that it is unlikely to be a good practice to try to jam all possible events into one event processor per component. It'll become rather complicated. Instead, a number of small processors can be used and when their proceedings are ready to be aggregated, they can trigger aggregation events themselves.

License

Reactuate Events is licensed under the terms of the Apache 2.0 license.