Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rbxts/streamable

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rbxts/streamable

Observe instances that stream in and out of existence

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 27 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc