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

delightful-bus

v0.7.3

Published

Event bus with more features

Downloads

1,040

Readme

Delightful bus

Event bus with more features

Installation

$ yarn add delightful-bus
import Eventbus from "delightful-bus"

const bus = new Eventbus()

Classic methods

.emit(evt, ...args) - emit event
bus.emit("foo", "bar", "baz")
.on(evt, cb) - add event listener
bus.on("foo", console.log)
// => bar baz (According to previous example)
.once(evt, cb) - add self-destructable event listener
bus.once("foo", console.log)

bus.emit("foo", "bar", "baz")
// => bar baz

bus.emit("foo", "bar", "baz")
// => nothing (event was removed)
.off(evt, cb) - remove event listener
bus.off("foo")

bus.emit("foo", "bar")
// => nothing because listener is removed

More fun

.onMany(events) - add many events
bus.onMany({
  foo: [cb1, cb2],
  bar: [cb3]
})
.offAll() - remove all listeners
bus.offAll()

Extending and inheritance

.sendTo(bus) - send events to another bus
const bus1 = new Eventbus()

const bus2 = new Eventbus()

bus1.on("foo", console.log)

bus1.sendTo(bus2)

bus2.emit("foo", "bar baz")
// => bar baz (bus2 got events from bus1)
.fork() - fork bus
const bus1 = new Eventbus()
bus1.on("aaa", console.log)

const bus2 = bus.fork()

bus2.emit("aaa", "bar")
// => bar (events are inherited from bus1)

bus.on("bbb", console.log)
bus2.emit("bbb", "bar")
// => nothing (because event was send to bus1 after fork)

bus2.on("ccc", console.log)
bus.emit("ccc", "bar")
// => nothing (because event was send to bus2 after fork)
.merge(bus2) - fork current bus with of events of both (bus and bus2) buses
const bus = new Eventbus()
bus.on("aaa", console.log)

const bus2 = new Eventbus()
bus.on("bbb", console.log)

const bus3 = bus.merge(bus2)
bus3.emit("aaa", "bar")
// => bar (event from bus)
bus3.emit("bbb", "bar")
// => bar (event from bus2)

bus3.on("ccc", console.log)
bus.emit("ccc", "bar")
// => nothing (it's a fork)
bus2.emit("ccc", "bar")
// => nothing (it's a fork)
.injectTo(instance) - adds .on, .off, .onMany, .offMany, .offAll and .emit methods of forked bus to some instance
const smth = {}

const bus = new Eventbus()
bus.on("test", console.log)

bus.injectTo(smth)
smth.on("foo", console.log)
smth.emit("foo", "bar")
// => bar

bus.emit("test", "bar")
// => bar (inherited from bus)

bus.on("test", console.log)
smth.emit("test", "bar")
// => nothing (it's a fork)

bus.emit("foo", "bar")
// => nothing (it's a fork)
.injectObserverTo(newInstance) - adds only .on and .off methods
const smth = {}

const bus = new Eventbus()
bus.on("test", console.log)

bus.injectObserverTo(smth)
smth.on("foo", console.log)
smth.emit("foo", "bar")
// => bar

bus.emit("test", "bar")
// => bar (inherited from bus)

bus.on("test", console.log)
smth.emit("test", "bar")
// => nothing (it's a fork)

bus.emit("foo", "bar")
// => nothing (it's a fork)