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

swatk6-emitter

v1.0.0

Published

A drop-in replacement for EventEmitter that can handle DOM-style events whose propagation can be stopped.

Downloads

4

Readme

swatk6-emitter

A drop-in replacement for EventEmitter that can handle DOM-style events whose propagation can be stopped.

This module exports two classes: .emitter and .event. The .emitter can be used as a basis for extending your own class, and the .event class can be used by itself or be extended to serve your needs for an in-transit cancelable event.

emitter

This class provides a drop-in replacement functionality for Node's official EventEmitter class. It's API-compatible for the most part, but it has a few subtle differences.

  • It does not care about maximum listener counts (it's just an excuse to tolerate bad programming).
  • The class internals look decidedly different from the official EventEmitter implementation, so any hacks building on interals abuse will not work.
  • This class does not optimize for single listeners (which are done without an Array in the official implementation), so it might lose a few cycles when compared to the original.*
  • Neither does it optimize for single or multiple arguments; the algorithm I used for extracting arguments is one that avoids that famed V8 slowdown bug.*
  • It supports an object-based (.event) event approach that allows for payload and result distribution among listeners (allowing the use of events for dynamically configurable filters and data modifiers) and cancelable events (that stop any subsequent listeners to be called).

*: If you experience significant slowdowns because of these optimization omissions, let me know in an issue and I'll reintroduce them to the codeline.

The only noticable signature difference is in .emitter.emit(), as it, beside the original signature, also supports the new signature for the .event objects:

.emitter.emit(<EventObject>) : in this case, would be an .event object or one that extends it.

event

This class can be used on its own as a basis for a generic event object, or it can be extended to suit your needs.

Methods

new event(eventName[,payload[,origin]])

  • eventName <String>: the event's name (or type, YMMV)
  • payload <any>: the event's payload, optional, defaults to null
  • origin <Function|Object>: the function or object that created the event, optional, defaults to null

Creates a new event object (constructor).

event.canPropagate()

  • returns <Boolean>

Returns true if the event is not canceled and can move on to the next listner, if there is one; false otherwise.

event.stopPropagation() event.stopImmediatePropagation() event.cancelEvent()

  • returns the event object itself, allowing for chaining

These cancel the current event, so it won't get to any subsequent listeners. They all do the same, the aliases are there for convenience.

event.getPayload() event.setPayload(newValue) event.getResult() event.setResult(newValue)

  • newvValue <any>
  • set* methods return the event object itself, allowing for chaining

Accessor methods for the event's built-in payload and result containers.

Properties

event.type: <String>

Contains the event name/type.

event.target: <Function|Object>

The event's origin function or object, as set by the third argument of the constructor, defaults to null.