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

@xassist/xassist-eventdispatcher

v1.0.2

Published

general eventdispatcher class

Downloads

35

Readme

@xassist/xassist-eventdispatcher

This module creates a general EventDispatcher class The class can beused to add listneres, and fire events.

Installation

If you use NPM, you can install the module via npm install xassist-eventdispatcher. Otherwise, you can download the latest minified file. Be aware any dependencies are not installed by default; you should consider downloading them yourself. If you want, you can install the complete library from github xassist, this includes all dependencies you may need.

The module uses UMD and supports AMD, CommonJS and vanilla environments. Using vanilla: the xaglobal is exported:

<script>
xa.EventDispatcher()
</script>

API

EventDispatcher()

The base function is the constructor-function for the class EventDispatcher.

EventDispatcher()
new EventDispatcher()

new is not needed since the constructor checks for the use of the keyword. EventDispatcher() requires no parameters.

Result for EventDispatcher()

EventDispatcher() returns a new class instance of the Class EventDispatcher

EventDispatcher(a).constructor.name===EventDispatcher

EventDispatcher returns 6 method:

  • registerEvent(): the method to register the events, so listeners can get attached
  • hasEvent(): a method to check if an event is registered
  • on(): add a listener to an event
  • once(): add a listener to an event, which will be removed when the event is fired the first time
  • fire(): fires an event
  • off(): removes a specific listener from an event

EventDispatcher has 1 own attributes:

  • _event[Object]:here all registered events and listeners are stored

EventDispatcher().registerEvent()

EventDispatcher().registerEvent() registers events so it can be triggered in the future

EventDispatcher().registerEvent(eventName [,defaultThis])

Parameters for EventDispatcher().registerEvent()

EventDispatcher().registerEvent() takes 2 parameters:

  • eventName [String]:a string with the name for the event itself
  • defaultThis [any datatype,defaults to: this]:the default execution-context for the listeners

Result for EventDispatcher().registerEvent()

registerEvent returns an error if the event was registered before.

EventDispatcher().hasEvent()

The method EventDispatcher().hasEvent() checks if an event was registered before.

EventDispatcher().hasEvent(eventName)

Parameters for EventDispatcher().hasEvent()

EventDispatcher().hasEvent() takes 1 parameters:

  • eventName [String]:a string with the name for the event itself

Result for EventDispatcher().hasEvent()

It returns a boolean indicating if the event was registered.

EventDispatcher().on()

The method EventDispatcher().on() adds a listener for a certain event.

EventDispatcher().on(eventName,callBack [, thisArg])

EventDispatcher().on() returns nothing.

Parameters for EventDispatcher().on()

EventDispatcher().on() takes 3 parameters:

  • eventName [String]:a string with the name for the event itself.
  • callBack [Function]:the function which needs to be executed when the event is trigered
  • thisArg [any datatype,defaults to: defaultThis]:an optional reference for thisArg, the callBack will be binded on trigger of the event (not before, so you could change the callBack if needed)

EventDispatcher().once()

The method EventDispatcher().once() adds a listener for a certain event.

EventDispatcher().once(eventName,callBack [, thisArg])

once() is exactly the same the same as on(), but the listener will only gets executed once, even when the event is trigerred multiple times. EventDispatcher().once() returns nothing.

Parameters for EventDispatcher().once()

EventDispatcher().once() takes 3 parameters:

  • eventName [String]:a string with the name for the event itself.
  • callBack [Function]:the function which needs to be executed when the event is trigered
  • thisArg [any datatype,defaults to: defaultThis]:an optional reference for thisArg, the callBack will be binded on trigger of the event (not before, so you could change the callBack if needed)

EventDispatcher().off()

The method EventDispatcher().off() removes a listener for a certain event.

EventDispatcher().off(eventName,callBack )

EventDispatcher().off() returns nothing.

Parameters for EventDispatcher().off()

EventDispatcher().off() takes 2 parameters:

  • eventName [String]:a string with the name for the event itself.
  • callBack [Function]:the listener which needs to be removed

EventDispatcher().fire()

The method EventDispatcher().fire() fires an event.

EventDispatcher().fire(eventName /*list of other arguments*/ )

EventDispatcher().fire() returns nothing.

Parameters for EventDispatcher().fire()

EventDispatcher().fire() takes 2 parameters:

  • eventName [String]:a string with the name for the event itself.
  • /list or arguments/ [any datatype]:all other arguments that will be passed to the listeners as arguments

DevDependencies

  • csv2readme: read csv file with fixed format and parse a readme markdown file
  • rimraf: A deep deletion module for node (like rm -rf)
  • rollup: Next-generation ES6 module bundler
  • tape: tap-producing test harness for node and browsers

License

This module is licensed under the terms of GPL-3.0.