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

message-bank

v1.0.5

Published

Subscribable message bank

Downloads

7

Readme

Message Bank

Build Status

Subscribable message bank.

MessageBank behaves subtly different than a standard message bus. Subscribing to a message type that has been dispatched previously the callback function will fire immediately.

API

###MessageBank(options:Object)

Creates a new message bank instance with predefined options.

var bank = new MessageBank();

####options.setup(callback:Function)

Alias for bank.setup(func)

var bank = new MessageBank({
  setup: function() { }  
});

####options.config(options:Object)

Alias for bank.config()

var bank = new MessageBank({
  config: [{
    type: 'SUPER',
    transform: function(data, opts) { }
  }]
});

###Bank().setup(callback:Function)

Calls callback function immediatly with MessageBank instance as function context. Inert function by default, provides entry point additional setup behavior not default to MessageBox

bank.setup(function() { });

###Bank().config(type:String, config:Object)

Also: Bank().config(config:Object) Bank().config(config:ObjectArray)

Method for configuring how dispatched data is handled for specific dispatch type. Currently only defines transform config option, but this is a good place to enter custom configuration to be used in a custom parse function.

####config.transform(callback:Function)

By default transform config is called with data and options as arguments during the parse phase of a dispatch call.

bank.config('SUPER', {
  transform: function(data, opts) {
    data.duper = opts.isNonsense ? false : data.duper;
    return data;
  }
});

###Bank().dispatch(type:String, data:Object, options:Object) Also: Bank().dispatch(dispatch:Object) Bank().dispatch(dispatch:ObjectArray)

Dispatches a payload of data to the MessageBank, any subscriptions matching the payload type will be called.

bank.dispatch('SUPER', { duper: true }, { isNonsense: true });

###Bank().subscribe(type:String, callback:Function, options:Object)

Subscribe to a specific type of dispatch payload, if previous payload exists callback will be called immediately. Subscribe returns an id that can used to unsubscribe later.

Subscribing to the * or ALL type will respond to all dispatches. Bank().subscribe(callback:Function, opts:Options) will do the same.

bank.subscribe('SUPER', function(data, opts) {
  console.log(data, opts);
})

#####options.immediate

By default subscriptions will be called immediately if a payload of that type exists, setting immediate:false will hold of on calling until the next dispatch.

bank.subscribe('SUPER', function(data, opts) {
  console.log(data, opts);
}, { immediate: false });

###Bank().unsubscribe(id:Integer)

Unsubscribe from a dispatch type using subscription ID returned when defining a subscription.

var id = bank.subscribe('SUPER', function() {
  // run only once
  bank.unsubscribe(id);
});

###Bank().parse(type:String, data:Object, options:Object)

Internal function for manipulating dispatched data expecting a result of { data: {}, options: {} } By default parse runs any transform configs, but it can be overwriten for custom behavior.