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/streamable

v0.1.0

Published

Observe instances that stream in and out of existence

Downloads

4

Readme

Streamable

A common problem in streamed Roblox experiences is dealing with the existence of instances on the client.

The Streamable package seeks to solve this complexity by providing a series of helper functions. These functions observe the existence of instances as they stream in and out of existence.

observeChild

function observeChild(
	parent: Instance,
	childName: string,
	observer: (child: Instance) => () => void,
): () => void

Observe the existence of a given child within a parent instance. The observer function is called each time that the child comes into existence, and the returned callback is called when the instance goes away.

The function returns a "stop" callback which can be called to stop and clean up the observation process entirely. If called while the given instance exists, the inner returned function (i.e. the function that runs when the instance goes away) is called too.

If the top-level parent is destroyed, the observation is automatically stopped.

const stop = observeChild(workspace, "Baseplate", (baseplate) => {
	print("Baseplate exists");
	return () => {
		print("Baseplate is gone");
	};
});

observeDescendant

function observeDescendant(
	parent: Instance,
	descendantName: string,
	observer: (descendant: Instance) => () => void,
): () => void

This is the same as observeChild, except it observes across all descendants of the given parent instance.

observeChildren

function observeChildren<T extends string>(
	parent: Instance,
	childrenNames: Record<T, string>,
	observer: (children: Record<T, Instance>) => () => void,
): () => void

Observes a collection of children within the given parent instance. When all children are present, the observer will be called. When any of the children are no longer present, the observer's returned function is called. In other words, this observer can guarantee the existence of a compound group of instances.

The returned function can be called to stop the observation process, which is also automatically called if the parent instance is destroyed.

const stop = observeChildren(
	workspace,
	{
		// Custom mapping of keys to instance names:
		Ground: "Baseplate",
		Spawn: "SpawnLocation",
	},
	(children) => {
		// Use the same keys from above to access the actual instances:
		print(children.Ground, children.Spawn);
		return () => {
			print("Ground and/or spawn no longer present");
		};
	},
)

observeDescendants

function observeDescendants<T extends string>(
	parent: Instance,
	descendantNames: Record<T, string>,
	observer: (descendants: Record<T, Instance>) => () => void,
): () => void

This is the same as observeChildren, except it observes across all descendants of the given parent instance.