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

dispatch-manager

v1.2.1

Published

Module that uses flux's dispatcher for making events and dispatchers easier to work with in your application.

Readme

DispatchManager

Contents

Summary

DispatchManager is a module that makes working with events in React faster/easier. The goal is to have a single module that coordinates events between different components throughout your application. DispatchManager uses Dispatcher instances from flux to organize your components' listeners by action.

Install

npm install --save dispatch-manager

Quick Start

Add the dispatch manager to your code

const DispatchManager = require('dispatch-manager');

Register any listeners. First parameter is an action, use any string identifier. Second parameter is a function that will get called any time the action is dispatched.

DispatchManager.register('some_action', myListener);
function myListener(payload){
  console.log(payload);
}

Call dispatch to trigger any functions listening to the same action. First parameter is the action (string identifier), second parameter is any data that you want to pass to listeners.

DispatchManager.dispatch('some_action', { hello: 'world' });

Methods

| register( action:string, listener:function ):string | | :---------------------------------------------------------------------------- | | Registers a function to be called when the specified action is dispatched. Returns a string token which can later be used to unregister the listener. |

| unregister( action:string, token:string ):boolean | | :---------------------------------------------------------------------------- | | Unregisters a listener from the dispatcher associated with the specified action. Returns false if there is no dispatcher associated with the action. |

| dispatch( action:string[, payload:object] ):boolean | | :---------------------------------------------------------------------------- | | Triggers all listeners associated with the specified action. Optional payload as a second argument, accessed by the listener as the first parameter. |

| getDispatcher( action:string ):Dispatcher | | :---------------------------------------------------------------------------- | | Returns the dispatcher object assigned to the specified action. Returns false if it doesn't exist. |

Example

(Note: There is a working example that can be found in the 'example' folder. It was created using create-react-app, just run npm start within the folder.)

This is an example of how multiple components can listen for the same event triggered by any component. Assume that our react application structure is the following:

index.js
  - ComponentA.js
  - ComponentB.js
    - ComponentC.js

index.js

const React = require('react');
const ReactDOM = require('react-dom');
const ComponentA = require('./ComponentA');
const ComponentB = require('./ComponentB');

class App extends React.Component {
  render() {
    return (
      <div>
        <ComponentA/>
        <ComponentB/>
      </div>
    );
  }
}

ReactDOM.render( <App/>, document.getElementById('root') );

ComponentA.js

const React = require('react');
const DispatchManager = require('dispatch-manager');

class ComponentA extends React.Component {
  constructor(props){
    super(props);

    this.state = {
      actionHappened: false
    }

    /* 
    * Tell DispatchManager this component wants to know 
    * whenever 'some-action' is triggered in the app. 
    * When that happens, call onSomeAction().
    */
    DispatchManager.register( 'some-action', this.onSomeAction.bind(this) );
  }
  onSomeAction(){
    this.setState({ actionHappened : true });
  }
  render(){
    let message = (this.state.actionHappened) ? 'Some action happened!' : 'Listening for some action...' ;
    return (
      <div>A: {message}</div>
    );
  }
}

module.exports = ComponentA;

ComponentB.js

const React = require('react');
const DispatchManager = require('dispatch-manager');
const ComponentC = require('./ComponentC');

class ComponentB extends React.Component {
  constructor(props){
    super(props);

    this.state = {
      actionHappened: false
    }

    /* 
    * Tell DispatchManager this component also wants to know 
    * whenever 'some-action' is triggered in the app. 
    * When that happens, call onSomeAction().
    */
    DispatchManager.register( 'some-action', this.onSomeAction.bind(this) );
  }
  onSomeAction(){
    this.setState({ actionHappened : true });
  }
  render(){
    let message = (this.state.actionHappened) ? 'Some action happened!' : 'Listening for some action...' ;
    return (
      <div>
        <div>B: {message}</div>
        <ComponentC/>
      </div>
    );
  }
}

module.exports = ComponentB;

ComponentC.js

const React = require('react');
const DispatchManager = require('dispatch-manager');

class ComponentC extends React.Component {
    onButtonClick() {
      /*
      * When the button is clicked, tell DispatchManager 
      * to tell any components listening to 'some-action'.
      * When dispatching, you can also pass data as the second
      * argument, which can be accessed as a parameter in the listeners.
      *
      * e.g DispatchManager.dispatch( 'some-action', { foo: 'bar' } );
      */
      DispatchManager.dispatch('some-action');
    }
    render() {
        return (
            <div>
                C: <input type="button" onClick={this.onButtonClick.bind(this)} defaultValue="DO 'some-action' !" />
            </div>
        );
    }
}

module.exports = ComponentC;

Result

Clicking the button on ComponentC should display 'Some action happened!' on both ComponentA & ComponentB.