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

@rbxts/object-event

v1.1.0

Published

Allows for custom events to be created for custom OOP implementations. Attempts to reproduce Roblox's syntax as closely as possible while adding more features.

Downloads

12

Readme

This NPM Package for Roblox-TS allows developers to implement custom Events for custom classes, without resorting to BindableEvents.

This should be particularly useful for projects that heavily rely on the OOP paradigm for libraries and other game components.

The module can be used both in pure Lua(u) scripts (via Rojo or any other way) or with Roblox-TS (includes compile-time type-checking).

Example

/////// Module.ts ///////

import ObjectEvent from "@rbxts/object-event"

const event = new ObjectEvent<[number, String, Vector3]>()

event.Connect((id, msg, position) => {
    // We can safely assume that:
    // id is a number
    // msg is a string
    // position is a Vector3
})

export event


/////// Waiter.server.ts ///////

import {event} from "./Module"

event.Fire(10, "oof", new Vector3(1, 2, 3))  // all good
event.Fire(10, "oof")                        // will not compile!

export {}

To allow all kinds of arguments, of any number:

let event = new ObjectEvent<[...unknown]>()

ObjectEvent API

  • Connect(f) - f is a function that takes the arguments typed accordingly and returns void. Returns an ObjectEventConnection
  • Wait() - yields the thread until the event is fired. Returns the values typed accordingly.
  • Fire(...) - fires the event. Arguments must be the same number and type of the event.
  • Event - an RBXScriptSignal-like interface supporting the Connect() and Wait(), just in case you prefer to use it as a BindableEvent.
  • SubscribedConnections - an array of ObjectEventConnections with all the connections currently listening to the event.

ObjectEventConnection API

  • Disconnect() - disconnects from the event
  • Reconnect() - reverts a disconnection
  • IsConnected() - returns true if the connection is listening to the event (this is, not Disconnect()'ed), false otherwise.
  • Event - the ObjectEvent associated with this connection
  • Listener - the function associated with this connection

Current Features:

  • Standard Roblox Event Feature Set:
    • Connecting to an event;
    • Disconnecting a connection;
    • Yielding a thread until the event is fired;
    • Passing arguments through the functions;
  • Custom features:
    • Reconnecting a disconnected connection without having to make a new one (ability to reuse connections).
    • Reading all active connections for a given event.

Goals:

  • Abstraction from internals;
  • Roblox-like syntax while keeping a minimum of decency for TypeScript syntax;
  • Code readability for OOP implementations.
  • Complement Roblox's implementation with extra (useful) features.