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

eventery

v0.0.4

Published

A tiny publish-subscribe library for JavaScript, specifically tailored for use in games:

Downloads

1,039

Readme

Eventery

A tiny publish-subscribe library for JavaScript, specifically tailored for use in games:

  • Instantiate event objects with typed arguments.
  • Supports events with zero, one, or multiple typed arguments; no need to create extra payload objects for events with multiple arguments.
  • Events support synchronous and asynchronous publishing.
  • Events provide their own events that notify about new or removed subscribers.
  • Zero dependencies!

Usage

import { Event } from "eventery";

/* Create an event. You can pass a type to describe the event's
payload arguments. These may optionally be named, like here: */
const event = new Event<[deltaTime: number]>();

/* Create a callback and add it as a subscriber. */
function callback(dt: number) {
  console.log(dt);
}

event.subscribe(callback);

/* Publish an event. The subscribers will be invoked synchronously. */
event.publish(123);

/* Unsubscribe the callback. */
event.unsubscribe(callback);

/* Clear all subscribers. */
event.clear();

Event Payloads

Event payloads are typed using TypeScript's tuple syntax. For example, the following event has a payload with two arguments:

const event = new Event<[number, number]>();

These arguments may optionally be named:

const event = new Event<[x: number, y: number]>();

Payload arguments can be made optional:

const event = new Event<[dt: number, context?: string]>();

They can use the ... syntax to indicate that the argument is a rest parameter:

const event = new Event<[context: string, ...deltas: number[]]>();

Subscribe/Unsubscribe Notification Events

Event provides two events that notify about new or removed subscribers:

import { Event } from "eventery";

const event = new Event<[number]>();

/* Subscribe to the event that notifies about new subscribers. */
event.onSubscribed.subscribe((callback) => {
  console.log("New subscriber:", callback);
});

/* Subscribe to the event that notifies about removed subscribers. */
event.onUnsubscribed.subscribe((callback) => {
  console.log("Removed subscriber:", callback);
});

const callback = function (dt: number) {
  console.log(dt);
};

/* Subscribe a callback. This will trigger all `onSubscribe` callbacks. */
event.subscribe(callback);

/* Unsubscribe the callback. This will trigger all `onUnsubscribe` callbacks. */
event.unsubscribe(callback);

License

Copyright (c) 2023 Hendrik Mans

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.