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

smelly-event-emitter

v0.1.1

Published

A minimal and fast event-emitter for the browser.

Downloads

44

Readme

Smelly Event Emitter

A minimal and fast event-emitter for the browser. This can be used as a standalone class or attached to an existing objects prototype. See usage example below.

Installation

npm

npm install smelly-event-emitter --save

browser

<script src="/source/to/event-emitter.min.js"></script>

Usage

commonjs environment with inheritance (ES6)

import EventEmitter from 'event-emitter';

class Foo extends EventEmitter {
  constructor() {
    super();
    
    this.on('foo', this.bar);
    this.emit('foo');
  }
  
  bar() {
    console.log('foo event emitted!');
  }
}

commonjs environment with inheritance (ES5)

var EventEmitter = require('smelly-event-emitter');

function Foo() {
  EventEmitter.call(this); // super
  
  this.on('foo', this.bar);
}

Foo.prototype.bar = function() {
  console.log('foo event emitted');
}

Foo.prototype = Object.create(EventEmitter.prototype);
Foo.prototype.constructor = Foo;

var test = new Foo();
test.emit('foo');

browser environment with inheritance

function Foo() {
  EventEmitter.call(this); // super
  
  this.on('foo', this.bar);
}

Foo.prototype.bar = function() {
  console.log('foo event emitted');
}

Foo.prototype = Object.create(EventEmitter.prototype);
Foo.prototype.constructor = Foo;

var test = new Foo();
foo.emit('foo');

standalone (commonjs ES6)

import EventEmitter from 'event-emitter';

const ee = new EventEmitter();

class Foo {
  constructor() {
    ee.on('foo', this.bar);
    ee.emit('foo');
  }
  
  bar() {
    console.log('foo event called');
  }
}

API

.on(eventName, listener)

Attaches a listener to an event name. The listener can be removed by calling .off(eventName, listener). Note that if you pass an anonymous function as the lister, the .off() method will not be able to correctly remove that listener from the event listener list.

.off(eventName, listener)

Removes a listener from an event name. The listener will only correctly be removed if it is a named function (with the exception of if there is only a single listener attached).

.once(eventName, listener)

Attaches a listener to an event name that will only be fired once and then removed after being fired.

.emit(eventName, ...args)

Fire off all listeners for a specified event name and pass in any params to them as well. You can pass in any number of arguments you want e.g. this.emit('foo', 'bar', 'baz', 'boz') or this.emit('foo', { bar: 'baz' }). Note, a listener must have been attached with .on() or .once() before it can be fired with .emit().

.getMaxListeners()

Gets the specified maxListener count for the EventEmitter. Note this is used only to warn you against attaching too many listeners at once to a single event name.

.setMaxListeners()

Sets the maxListener count for the EventEmitter.

.getAllListeners(eventName = null)

Grabs all listeners for a specific event name, or if none is provided simply grabs the entire EventEmitter listeners object.