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

@ponchojs/eventbus

v1.1.0

Published

Light weight event bus for JavaScript and TypeScript written in TypeScript with complete type integration.

Downloads

14

Readme

@ponchojs/eventbus

Light weight event bus for JavaScript and TypeScript written in TypeScript with complete type integration.

In order for the event bus to work it is necessary to use ES6 or higher.

Usage

First import the package with ESM or CommonJS:

import EventBus from '@ponchojs/eventbus';

const EventBus = require('@ponchojs/eventbus');

In order to use the eventBus you will need to create a new instance of it:

const eventBus = new EventBus();

Adding an event listener

You can simply add an event listener by calling the on function on your event bus. The first value is the event it should listen to. This has to be a class, function or string. The second parameter is the callback function which will be called when the event is emitted.

The return value of this function will be the function which unsubscribes this listener from the event bus.

const subscribtion = eventBus.on(NewEvent, event => console.log(event));

const subscribtion = eventBus.on('event', event => console.log(event));

Removing an event listener

When you add an event listener it will return a function. When it is called the event listener will be removed from the event bus. If the listener was removed successfully it will return true otherwise false.

const removed = subscribtion.detach();

Emitting an event

With the emit or post function you can emit a new event on the event bus. This function simply takes your event data as input.

eventBus.emit(new NewEvent('This is data'));

eventBus.post(new NewEvent('This is data'));

eventBus.emit('event');

eventBus.post('event');

TypeScript and typing

Since this package uses' typescript it is possible to get all the type information about the event you are listening to. This helps while developing your callbacks and also allows the typescript compiler to recognize errors in your type usage.

Bugs and feature suggestions

If you find any bugs or have any feature suggestions feel free to create a new issue on the issue tracker.