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-reactive-tools

v0.2.0

Published

Reactive tools for React.js

Downloads

451

Readme

Reactive tools for React.js

  • createState - create state reactive variable that can be get and set from everywhere and subscribed to changes in react components
  • createStateMap - create state reactive variable that can be get and set from everywhere and subscribed to changes in react components
  • createAction - create action that can be dispatched from everywhere and subscribed in react components
  • createCustomPubSub - create a custom PubSub that can publish from everywhere and subscribe by channel in react components
  • createFixedPubSub - create a preconfigured PubSub that can publish from everywhere and subscribe by channel in react components

Examples:

Create a new reactive state of generic type:

const exampleState = createState<number>(0);

Update the state:

exampleState.set(10);

Get the state from everywhere:

const example = exampleState.get();

Subscribe for state updates in react components:

const example = exampleState.subscribe();

Get the state from everywhere ( with prev value ):

const { prev, current } = exampleState.get(true);

Subscribe for state updates in react components ( with prev value ):

const { prev, current } = exampleState.subscribe(true);

Reset the state from everywhere and return it to initial value:

exampleState.reset();

Create a new reactive state map of generic type:

const exampleStateMap = createStateMap<number>(0);

Update the state by some key (string | number):

exampleStateMap.set('key', 10)

Get the state by key from everywhere:

const example = exampleStateMap.get('key')

Subscribe for state updates by key in react components:

const example = exampleStateMap.subscribe('key');

Get the state of whole map from everywhere:

const example = exampleStateMap.getMap()

Subscribe for state updates of whole map in react components:

const example = exampleStateMap.subscribeMap();

Reset state by key and return it to initial value:

const example = exampleStateMap.reset('key');

Reset state for whole map and return it to initial value:

const example = exampleStateMap.resetMap();

Create a new reactive action of generic type (can be and void):

const exampleAction = createAction<string>();

Dispatch action from everywhere:

exampleAction.dispatch("Hi")

Subscribe for action in react components

exampleAction.subscribe(useCallback((value) => {
    console.log(`Action with value: ${value}`);
}, []))

Create a new PubSub:

const customPubSub = createCustomPubSub('customPubSub');

Publish to channel from everywhere:

customPubSub.publish<string>('someChannelName', 'World!')

Subscribe by channel in react components

customPubSub.subscribe<string>("someChannelName", useCallback((value) => {
    console.log(`Hello ${value}`);
}, []))

Also supports void pub/sub for action trigger

Create a new PubSub with predefined channel config:

type PubSubConfig = {
    channel: "channel1",
    dataType: string,
} | {
    channel: "channel2",
    dataType: number,
}

const fixedPubSub = createFixedPubSub<PubSubConfig>('fixedPubSub')

Publish to channel from everywhere:

fixedPubSub.publish('channel1', 'World!')

Subscribe by channel in react components

fixedPubSub.subscribe("channel1", useCallback((value) => {
    console.log(`Hello ${value}`);
}, []))

Also supports void pub/sub for action trigger