Skip to main content

Binder

A binder allows you to bind a Luau class to instances with certain tags. For example:

local MyClass = {}
MyClass.__index = MyClass

function MyClass.new(robloxInstance)
	print("New tagged instance of ", robloxInstance)
	return setmetatable({}, MyClass)
end

function MyClass:Destroy()
	print("Cleaning up")
	setmetatable(self, nil)
end

-- bind to every instance with tag of "Yellow"
local binder = Binder.new("Yellow", MyClass)
binder:Start() -- listens for new instances and connects events

Types

ClassInterface<T>

interface ClassInterface<T> {
new(instanceInstance) → T
Destroy(T) → ()
}

Basic requiremnts for a class to be able to be used by a Binder

BinderConfig

interface BinderConfig {
Tags{string}
Ancestors{Instance}
Classes{string}
}
local config = {
	Tags = { "Blue", "Red" }, -- Has tag "Blue" AND "Red"
	Classes = { "BasePart", "Model" }, -- Is a BasePart OR Model
	Ancestors = { Workspace, ReplicatedStorage } -- In Workspace OR ReplicatedStorage
}

Functions

new

Binder.new(
tagstring | BinderConfig,
classClassInterface<T>
) → Binder<T>

Create a new binder You can either pass a single tag string, or you can pass a config which gives more fine-grain control over what instances you would like.

Start

Binder.Start(selfBinder<T>) → ()

Connects the CollectionService events needed to listen to tags.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Create a new binder You can either pass a single tag string, or you can pass a config which\ngives more fine-grain control over what instances you would like.",
            "params": [
                {
                    "name": "tag",
                    "desc": "",
                    "lua_type": "string | BinderConfig"
                },
                {
                    "name": "class",
                    "desc": "",
                    "lua_type": "ClassInterface<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Binder<T>\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 106,
                "path": "packages/binder/source/init.luau"
            }
        },
        {
            "name": "_HasInstanceGotAClass",
            "desc": "Check if `instance` has a class creted for it.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Binder<T>"
                },
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "static",
            "private": true,
            "source": {
                "line": 164,
                "path": "packages/binder/source/init.luau"
            }
        },
        {
            "name": "_Add",
            "desc": "Create a class for the `instance`, as well as checking if it fits the [BinderConfig] and it doesn\nnot yet have a class.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Binder<T>"
                },
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "static",
            "private": true,
            "source": {
                "line": 173,
                "path": "packages/binder/source/init.luau"
            }
        },
        {
            "name": "_Remove",
            "desc": "Destroys the `instance`'s class if it has one.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Binder<T>"
                },
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "static",
            "private": true,
            "source": {
                "line": 189,
                "path": "packages/binder/source/init.luau"
            }
        },
        {
            "name": "Start",
            "desc": "Connects the [CollectionService] events needed to listen to tags.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Binder<T>"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 204,
                "path": "packages/binder/source/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "_Tag",
            "desc": "The [CollectionService] tag to bind to",
            "lua_type": "string",
            "private": true,
            "source": {
                "line": 85,
                "path": "packages/binder/source/init.luau"
            }
        },
        {
            "name": "_Class",
            "desc": "Class table which should contain the constructor & destructor of the class.",
            "lua_type": "ClassInterface<T>",
            "private": true,
            "source": {
                "line": 93,
                "path": "packages/binder/source/init.luau"
            }
        },
        {
            "name": "_ClassInstances",
            "desc": "A map of instances to their class instances.",
            "lua_type": "{ [Instance]: ClassInterface<T> }",
            "private": true,
            "source": {
                "line": 101,
                "path": "packages/binder/source/init.luau"
            }
        }
    ],
    "types": [
        {
            "name": "ClassInterface<T>",
            "desc": "Basic requiremnts for a class to be able to be used by a Binder",
            "fields": [
                {
                    "name": "new",
                    "lua_type": "(instance: Instance) -> T",
                    "desc": ""
                },
                {
                    "name": "Destroy",
                    "lua_type": "(T) -> ()",
                    "desc": ""
                }
            ],
            "source": {
                "line": 13,
                "path": "packages/binder/source/init.luau"
            }
        },
        {
            "name": "BinderConfig",
            "desc": "```lua\nlocal config = {\n\tTags = { \"Blue\", \"Red\" }, -- Has tag \"Blue\" AND \"Red\"\n\tClasses = { \"BasePart\", \"Model\" }, -- Is a BasePart OR Model\n\tAncestors = { Workspace, ReplicatedStorage } -- In Workspace OR ReplicatedStorage\n}\n```",
            "fields": [
                {
                    "name": "Tags",
                    "lua_type": "{ string }",
                    "desc": ""
                },
                {
                    "name": "Ancestors",
                    "lua_type": "{ Instance }",
                    "desc": ""
                },
                {
                    "name": "Classes",
                    "lua_type": "{ string }",
                    "desc": ""
                }
            ],
            "source": {
                "line": 33,
                "path": "packages/binder/source/init.luau"
            }
        }
    ],
    "name": "Binder",
    "desc": "A binder allows you to bind a Luau class to instances with certain tags. For example:\n\n```lua\nlocal MyClass = {}\nMyClass.__index = MyClass\n\nfunction MyClass.new(robloxInstance)\n\tprint(\"New tagged instance of \", robloxInstance)\n\treturn setmetatable({}, MyClass)\nend\n\nfunction MyClass:Destroy()\n\tprint(\"Cleaning up\")\n\tsetmetatable(self, nil)\nend\n\n-- bind to every instance with tag of \"Yellow\"\nlocal binder = Binder.new(\"Yellow\", MyClass)\nbinder:Start() -- listens for new instances and connects events\n```",
    "source": {
        "line": 62,
        "path": "packages/binder/source/init.luau"
    }
}