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

obeservable

v1.0.1

Published

Different observable and - contrary to the name - lightweight objects.

Downloads

2

Readme

obeservable

General

Different observable and - contrary to the name - lightweight objects. To be fair, in the end it's something everyone could do with a bit of time, but why reinvent the wheel?

How often did you need an Eventbus and created it from scratch again and again?
How often did you need an Observable Array or HashMap and recreated them once again?

Never? Fair enough. But if you need those - check out this package.

Why "obeseverable"?

It was a typo that I realized too late and I just went with it and created that terrible joke in the description.

Features

Current

  • Eventbus

Upcoming

  • ObservableMap
  • ObservableArray
  • whatever you suggest and makes sense

Docs

Eventbus

General

With an Eventbus you can create, listen to and emit events from anywhere in your application, to do stuff depending on other stuff that happened.
If you're familiar with Events in the Browser or HTML, then this will be quite familiar.

Usage

Create and get Eventbuses

Creating an Eventbus is as simple as creating a new Instance of any object.

const bus = new Eventbus('some_name')

You can create as many buses as you wish... if you ever need one than more. Also, you don't need to store your event bus in some window or global. Eventbus itself contains a map with all your created buses that you can then get as you need them. Simply call the static .get() method and if you want to have more than one bus, destructure the result. You can get more buses with a simple space between their names.

const { some_bus, some_other_bus, yes_bus } = Eventbus.get('some_bus some_other_bus yes_bus')

Create, listen to and emit Events

Events only work on Eventbus instances - therefore you first need to create one. You can then add events to the bus via .on() or .once() methods. .on() will execute every time an event is emitted, while once() will only be executed the next time the event gets emitted. You can emit an event with .emit().

const restaurant = new Eventbus('restaurant')
restaurant.on('order', order_details => console.log(order_details))
restaurant.on('pay', payment_details => console.log(payment_details))
restaurant.once('get_insurance', insurance_amount => console.log(insurance_amount))

restaurant.emit('order', { food: 'Pizza', drink: 'Beer' })
restaurant.emit('order pay', { food: 'Sushi', drink: 'Sake' })
restaurant.emit('order', { food: 'Pasta', drink: 'Water' })

restaurant.emit('get_insurance', 2000)
restaurant.emit('get_insurance', 5000) // won't happen - sorry :(

Get Events

You can get all event names and their specific permanent and one-shot events with the .get() method. Most probably you won't need this, but maybe it's good for debugging purposes. When given a name you can also only get specific event names.

const bus = new Eventbus('somebus')
bus.on('some_event', () => {})
bus.on('yes_no_event', () => {})
bus.on('some_other_event', () => {})
bus.once('some_other_event', () => {})

const ev1 = bus.get() // to get all event names and their events
const ev2 = bus.get('some_event some_other_event') // to get only those

console.log(ev1)
console.log(ev2)

Result:

{ some_event: { once: [], every: [ [Function] ] }, yes_no_event: { once: [], every: [ [Function] ] }, some_other_event: { once: [ [Function] ], every: [ [Function] ] } }
{ some_event: { once: [], every: [ [Function] ] }, some_other_event: { once: [ [Function] ], every: [ [Function] ] } }

Clear Buses and Events

You can clear buses and events with their respective .clear() Function. Once again: If given the names, you can only clear the specific buses/events(on the bus) or everything if the parameter is empty.

Eventbus.clear() // kill everything
Eventbus.clear('some_bus some_other_bus') // kill only those two

const bus = new Eventbus('bla')
bus.on('bla', () => {})
bus.on('palawa', () => {})
bus.on('joko', () => {})

bus.clear('bla joko') // kill only bla and joko
bus.clear() // kill everything