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

events-map

v0.2.0

Published

An events map which stores registered events in a convenient way.

Downloads

1

Readme

Events Map

Events Map is a utility module which aims to provide you with a convenient way to register events and manager them later on. Event handlers can automatically be bound to a context and later on be unregistered without event providing their bound version.

Example

import EventsMap from 'events-map';

class Component {
  constructor() {
    // Here we create a new instance of the events map, and we invoke it with the current
    // context, thus, any event handler which would be registered from now on, will be
    // bound automatically to the current context
    this.events = new EventsMap(this);

    this.events.on(document, 'mousedown', this.handleMousedown);
  }

  handleMousedown() {
    // Note that the context represents the current component
    this.mousedownTime = Date.now();

    this.events.on(document, 'mouseup', this.handleMouseup);
  }

  handleMouseup() {
    this.mouseupTime = Date.now();

    // Will unregister only the registered 'mouseup' event of the current component
    this.events.off(document, 'mouseup');

    const mouseholdTime = this.mouseupTime - this.mousedownTime;

    console.log(`mouse held for ${mouseholdTime}ms`);
  }

  dispose() {
    // All registered event listeners can automatically be unregistered by simply not
    // specifying anything when calling the 'off()' method
    this.events.off();
  }
}

export default Component;

Using Speech Tree you can:

  • Register events for incoming speech based on its content.
  • Register a sequence of events which should follow each other in a specific order.
  • Analyze a sentence using user-defined methods.
  • Label a sentence against the server using a user-defined classifier.

Speech Tree is not supposed to provide you with a full robust solution, but rather an extensible one which can be changed based on the user's desires and needs.

API

EventsMap([Object]) class

description: The events mapping class which will take care of registering and unregistering events bound to a specified context. Accepts an optional argument which specifies the context of registered events. If not provided, will default to the global window object.

methods:

  • on(EventTarget, String, Function, [Boolean]) - Accepts the event target, event name, event handler and an optional capture usage specifier which will default to false. Will register the specified event to the specified event target.
  • once(EventTarget, String, Function, [Boolean]) - Same as the on(), only registers a one-time event listener which will be unregistered right after its first invocation.
  • off([EventTarget|Boolean], [String|Boolean], [Function|Boolean], [Boolean]) - Unregister an event listener based on specified parameters. If all parameters were provided, it will unregister the specified event as usual. If no event handler was provided, will unregister all the event handlers which match the other parameters. If no event name was provided, will unregister all the event names which match the other parameters. If not event target was provided, will unregister all the events completely. The last argument is a flag which specifies capture usage.
  • emit(EventTarget, String) - Emits an event which will trigger the event name belonging to the specified event target.

Download

The source is available for download from GitHub. Alternatively, you can install using Node Package Manager (npm):

npm install events-map

License

MIT