Socket
Book a DemoInstallSign in
Socket

@rbxts/atomic-binding

Package Overview
Dependencies
Maintainers
0
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rbxts/atomic-binding

Types for AtomicBinding module

0.8.1
latest
Source
npmnpm
Version published
Weekly downloads
38
Maintainers
0
Weekly downloads
 
Created
Source

Atomic Binding

The credit for the original source code goes to Roblox. The contents of this file were taken from Roblox-provided AtomicBinding ModuleScript located under the RbxCharacterSounds LocalScript, which itself is located in the StarterPlayerScript service.

Basic Usage

Note that there is autocomplete support for alias values. You should use slash (/) to see the possible paths.

type Character = Model & {
	Humanoid: Humanoid & {
		Animator: Animator;
	};
	HumanoidRootPart: BasePart;
};

// Notice how we first invoke an empty function.
const bindingFromBase = createAtomicBinding<Character>()({
    animator: "Humanoid/Animator",
    humanoid: "Humanoid",
    rootPart: "HumanoidRootPart",
}, ({ root, animator, humanoid, rootPart }) => {
    // do something with "Animator"
    // do something with "Humanoid"
    // do something with "HumanoidRootPart"

    return () => {
        // Disconnect all "instances" related connections
    };
});

const manifest = createManifest<Character>({
    animator: "Humanoid/Animator",
    humanoid: "Humanoid",
    rootPart: "HumanoidRootPart",
})

const binding = createAtomicBinding(manifest, ({ root, animator, humanoid, rootPart }) => {
    // do something with "Animator"
    // do something with "Humanoid"
    // do something with "HumanoidRootPart"

    return () => {
        // Disconnect all "instances" related connections
    };
})

const character = {} as Character

// some CharacterAdded event handler
binding.bindRoot(character);

// some CharacterRemoving event handler
binding.unbindRoot(character);

binding.destroy();

The "getInstanceFromPath" function is quite helpful when we just want to ensure that the instance exists at the provided path.

type SomeModel = Model & {
    Particles: Folder & {
        Particle1: ParticleEmitter;
        Particle2: ParticleEmitter;
    }
}

const someModel = {} as SomeModel

const particle = getInstanceFromPath(someModel, "Particles/Particle1")
if (!particle) {
    return
}

The waitForInstanceFromPath function does the same as the getInstanceFromPath function, but instead utilizes WaitForChild method of the Instance. This means that the return type will never be undefined.

Keywords

roblox

FAQs

Package last updated on 14 Sep 2024

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.