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 🙏

© 2026 – Pkg Stats / Ryan Hefner

observable_js

v2.0.1

Published

An event system for JavaScript libraries.

Readme

Observable – A JavaScript event system Build Status

Observable is a JavaScript mixin for adding observer methods to a function. It's similiar to the jQuery event system, but can be added into any other module. You can use it for your own JavaScript libraries.

Usage

npm install observable_js or copy the source from lib/observable.js. Observable will be assigned to the global scope if you don't use node and no other AMD or CommonJS loader is present.

ES6:

class MyLibrary extends Observable {  }

CoffeeScript:

class MyLibrary extends Observable

Other usages:

// Adding the Observable methods to an existing object:
Observable.mixin(a)

// Add the methods to the prototype of a constructor function
Observable.mixin(Constructor.prototype)

// Create a new object that has all the Observable methods
var a = new Observable()

Features

  • Super easy to use for your library, just extend from it or mixin the methods
  • Most methods are overloaded, making the API very nice to use
  • All methods are chainable
  • It's very well tested
  • Node / NPM and the browser are both supported

Documentation

The object that gains the observable methods will be called x in this README for convenience.

on: subscribing to events

You can watch a single event:

var id = x.on('topic', fn);

You can also watch several events at once:

var ids = x.on(['topic1', 'topic2'], fn);

Or watch several events at once that need different handlers:

var ids = x.on({
  topic1: fn,
  topic2: fn2
});

once

The once method behaves exactly like on and accepts the same arguments, but after triggering the event for the first time the event will be removed.

x.once('topic', fn);
x.trigger('topic'); // fn will be triggered
x.trigger('topic'); // fn won't be triggered, event doesn't exist anymore

trigger: firing events

Calling .trigger('topic') will execute all function subscribed to 'topic'.

x.on('topic', function () {
	console.log('topic called');
});
x.trigger('topic'); // Logs 'topic called'

You can also pass arguments to the subscribed functions by passing an array as the second argument:

x.on('topic', function (arg1, arg2) {
	console.log(arg1, arg2);
});
x.trigger('topic', [[1, 2], true]); // Logs [1, 2] and true

off: unsubscribing from events

This method accepts the exact same arguments as on and once. You pass the topic and the functions you want to unsubscribe. Observable will only remove the passed function from the topic.

x.on('topic', fn),
x.off('topic', fn);

x.on(['topic2', 'topic3'], fn2);
x.off(['topic2', 'topic3'], fn2);

x.on({ topic: fn })
x.off({ topic: fn })

You can call off without any arguments to remove all events. You should only do this if you know what you're doing!

x.off();

Chaining

All methods return the parent object so you can use chaining.

x.on('topic', fn).off('topic2').trigger('topic3');

Projects that use Observable

Observable ports