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

pubus

v1.0.0

Published

pubus is an event bus sytem for Node.js.

Downloads

1

Readme

pubus

Yes, this is an other event bus system.

Sometime we don't need the event be sent immediately, maybe hoped it can be slowly, so the Pubus bus can do it.

Now, every event will be controlled by event loop manager, after one event listenter is done, the next listenter will not work immediately, it will wait sometimes for work, the blood of event will not be happened.

And I was hate the remove listener method in other event manager, you have to pass the callback function for the param, so you can not use anonymous function, because it only not have function's name, why we have to use outdated way? so I use TAG instead of callback function, you can remove listenter use TAG, it is string, it is so easily to use, you can use anonymous function now!

Install

You can install use npm or yarn

npm install pubus

OR

yarn add pubus

Usage

const Pubus = require('pubus').default;
// Or if you use Typescript you can do this
import Pubus from 'pubus';

// Initialize
const bus = new Pubus();

// Register listenter with anonymous function
bus.on('event-one', () => 
  console.log('Event One Emitted by anonymous function!')
})

// Register listenter with named function
function handlerEvent() {console.log('Event One Emitted by hadlerEvent')}
bus.on('event-one', handlerEvent);

// Add tag
bus.on('event-one', handlerEvent, 'event-one-tag');

// Emit event without payload
bus.emit('event-one')

// Emit event with payload
bus.emit('event-one', 'hello wold')

// Remove listener by tag
bus.off('event-one', 'event-one-tag')

API

  • constructor(throttle?)
  • Pubus#on(eventName, callback, tag?)
  • Pubus#addListener(eventName, callback, tag?)
  • Pubus#emit(eventName, ...payload)
  • Pubus#off(eventName, tag?)
  • Pubus#removeListenter(eventName, tag?)

constructor(throttle?)

This is construct function, the param throttle is the wait time for each task, the unit is ms and default vaule is 30ms, you can adjust it by yourself.

Pubus#on(eventName, callback, tag?)

Add listenter for event, like other event system, but you can add addtional param tag, then you can remove listenter by tag;

const bus = new Pubus();
bus.on('ready', () => {console.log('Ready!')}, 'tag-for-ready');

YES! you can use anonymous function NOW!��

Pubus#emit(eventName, ...payload)

This fire event, but event will not work immediately, when the event of same name was fired before, it will wait throttle time, and work. So the blood of event was not be happened.

Pubus#off(eventName, tag?)

It's used to remove listener, you can add the second param tag to remove special listener which registerd with tag. So anonymous function also can be removed.