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 🙏

© 2026 – Pkg Stats / Ryan Hefner

reastig

v1.3.1

Published

An event-based state management library for react

Readme

reastig

Event-based state management framework for react applications.

Instalation

NPM: npm install reastig

YARN: yarn add reastig

Idea

  1. Maintain the application state as a global ordered list of events
  2. Components can update the global state by sending a message to a topic
  3. Other components update their local state by subscribing to a topic and calling a reducer function

How it works

Produce a message

To produce a message call the Reastig.send(topic: string, message: any) method:

import Reastig from "reastig";

Reasting.send("topic-name", { hello: "world" });

Typically, you would do this from inside a component:

import Reastig from "reastig";
import React from "react";

function MyProducerComponent() {
  return (
    <button onClick={() => Reastig.send("topic-name", { hello: "world" })}>
      Click me
    </button>
  );
}

Consume messages

To consume messages, call the Reastig.consume(topic: string, consumer: (message: any) => void): string method.

To stop consuming messages, call the Reastig.unsubscribe(topic: string, consumerId: string) method.

import Reastig from "reastig";

const consumer = message => console.log(message);
const consumerId = Reastig.consume("topic-name", consumer);
// ... if you no longer need the subscription
Reastig.unsubscribe("topic-name", consumerId);

Typically, you would do this from a component:

import Reastig from "reastig";
import React from "react";

class MyComponent extends React.Component {
  constructor() {
    super();
    this.state = {};
  }

  componentDidMount() {
    this.consumerId = Reastig.consume("topic-name", this.consumeMessage);
  }

  consumeMessage(message) {
    // consume the message (typically update component state)
    // ...
    this.setState(/** new state */);
  }

  componentWillUnmount() {
    Reastig.unsubscribe("topic-name", this.consumerId);
  }

  render() {
    return <div>State: {JSON.stringify(this.state)}</div>;
  }
}

Consuming is also available as a react hook:

import { useConsumer } from "reastig";
import React, { useState } from "react";

function MyComponent() {
  const [state, setState] = useState({});
  const consumer = message => setState(message);
  useConsumer("topic-name", consumer);

  return <div>State: {JSON.stringify(state)}</div>;
}

Update component state

A component typically consumes message in order to update its internal state with a reducer.

This pattern is available by calling the Reastig.subscribe(component: Component, topic: string, reducer: (oldState: any, message: any) => any) method.

Where the Component type's interface matches a react class-based component:

interface Component {
  state: any;
  setState: (newState: any) => void;
}

React class component subscribe example:

import Reastig from "reastig";
import React from "react";

const reducer = (oldState, message) => {
  return {
    oldState: oldState,
    message: message
  };
};

class MyComponent extends React.Component {
  constructor() {
    super();
    this.state = {};
  }

  componentDidMount() {
    this.consumerId = Reastig.subscribe(this, "topic-name", reducer);
  }

  componentWillUnmount() {
    Reastig.unsubscribe("topic-name", this.consumerId);
  }

  render() {
    return <div>State: {JSON.stringify(this.state)}</div>;
  }
}

Subscribing is also available as a react hook:

import React from "react";
import { useSubscriber } from "reastig";

function MyComponent() {
  const reducer = (oldCount, message) => oldCount + 1;
  const count = useSubscriber(0, "topic-name", reducer);

  return <div>Count is: {count}</div>;
}

You can subscribe the same state variable to multiple topics:

import React from "react";
import { useSubscribers } from "reastig"; // mind the plural

function MyComponent() {
  const reducer1 = (oldCount, message) => oldCount + 1;
  const reducer2 = (oldCount, message) => oldCount - 1;
  const count = useSubscribers(
    0,
    ["topic-name-1", reducer1],
    ["topic-name-2", reducer2]
    // ... as many as you want
  );

  return <div>Count is: {count}</div>;
}

Complete example

Check out the examples:

The examples were created with the react-create-app plugin. Install the dependencies using npm install or yarn install. Start them with npm start or yarn start.