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

@aeontek/eventservice

v1.0.16

Published

A service for creating, sending, and handling an event pattern implementation either locally or with WebSockets

Downloads

3

Readme

Classes

Interfaces

Message

Kind: global interface
Properties

| Name | Type | Description | | --- | --- | --- | | id | string | The unique identifier for this message. This may be valuable for distinguising between iterations of a single event that it called multiple times. | | destination | string | undefined | Optional. The intended recipient service of this message. If the service is not registered with the Server, the message will be ignored. If this argument is omitted, it is assumed that the Event is meant to be handled locally. | | origin | string | The service that the Event originated from. | | eventId | string | An identifier for the Event. While the identifier must be unique for Events on a service, different services may share Event identifiers. It is also possible for a single event to be raised multiple times. | | payload | T | Optional. If provided, this generic (T) object will be passed to events at the destination service as the data for event handlers. |

Client

Client Creates a WebSocket Client for handling events across different applications. Requires a running Server.

Kind: global class

client.run(port, serviceName, ip)

Initializes the EventService Client.

Kind: instance method of Client

| Param | Type | Description | | --- | --- | --- | | port | number | The port number to connect to. | | serviceName | string | The name of the service. Must be unique, and must be registered with the server. | | ip | string | If provided, the IP address of the WebSocket Server. If this is left null, then the Client will assume the WebSocket Server is hosted at localhost. |

client.send(message)

Sends a Message to the Server, which will route the message to its destination.

Kind: instance method of Client

| Param | Type | Description | | --- | --- | --- | | message | Message | The message object which contains the parameters needed to handle the message, as well as the message itself. |

client.stop()

Stops the client

Kind: instance method of Client

Event

Event The Event class contains methods for creating and managing event handlers.

Kind: global class

event.addListener(callback, id) ⇒ string

Adds a listener to the Event. If the Event is raised, then any registered listeners will be called.

Kind: instance method of Event
Returns: string - Returns the unique identifier of the event handler, which can be used to remove the listener.
Throws:

  • Invalid Identifier error if id is not unique

| Param | Type | Description | | --- | --- | --- | | callback | function | The function to call when the Event is raised. | | id | string | If provided, will act as the identifier for this event handler. The id must be uniquem or an error will be thrown. |

event.removeListener(id)

Removes a litener using its unique identifier

Kind: instance method of Event

| Param | Type | Description | | --- | --- | --- | | id | string | The unique identifier of the event to be removed. |

event.raise(data, destination)

Raises the Event. When an Event is raised, all of its event handlers are called.

Kind: instance method of Event

| Param | Type | Description | | --- | --- | --- | | data | any | The data that is sent along to an event handler as an argument | | destination | string | If a destination is specified and the service has been initalized as either a server or a client, then this will direct the server to forward this event to the correct service, given that the service is registered with the server. |

event.listListeners() ⇒ Array.<string>

Lists the unique identifiers of the current listeners.

Kind: instance method of Event

EventService

Service that handles the creation and management of events.

Kind: global class

EventService.Event(id) ⇒ Event

Event factory.

If called with the id of an existing Event, will return that Event. Otherwise, will create and return a new Event. If the service has been initalized as either a client or server, this will also add an event handler for pushing event data to the appropriate WebSockets.

Kind: static method of EventService

| Param | Type | Description | | --- | --- | --- | | id | string | The unique identifier for the event. |

Server

Server Creates a WebSocket Server for the managing of events across multiple applications. Allows connections only from Clients that have been registered using server.registerService(serviceName).

Kind: global class

server.run(port)

Runs the WebSocket Server, which listens for, processes, and emits the events that makes all the different services communicate. In order for the EventService to function between applications, exactly one must be functioning as a server.

Kind: instance method of Server

| Param | Type | Description | | --- | --- | --- | | port | number | The port to host the Server on. |

server.registerService(serviceName)

Adds the given service name to the list of registered services.

Kind: instance method of Server
Throws:

  • "Invalid Identifier" if the entry already exists.

| Param | Type | Description | | --- | --- | --- | | serviceName | string | The name of the service being added. |

server.send(message)

Sends a Message to the appropriate service, based on the Message.destination.

Kind: instance method of Server

| Param | Type | Description | | --- | --- | --- | | message | Message | The message object which contains the parameters needed to handle the message, as well as the message itself. |

server.stop()

Stops the server

Kind: instance method of Server