Skip to main content

Flux

A library for easily creating and managing reactive state.

Types

Function

type Function = (...any) → ...any

A generic function type

List

type List = {T}

A generic list type

Set

type Set = {[T]boolean}

A generic set type implemented as a table with boolean values

Dict

type Dict = {[T]any}

Represents a dictionary-like table with keys of type T and values of any type.

State

type State = {
_update(State<T>) → boolean,
_dependenciesSet<State<T>>,
_dependentsSet<State<T>>,
_binds{
[T]any,
_cleanupList<any>
},
_hooksDict<Function>,
_valueT,
_statefulboolean,
_operationList<any>?,
_tweenInfoTweenInfo | any,
set(
selfState<T>,
newT,
forceboolean?,
noTweenboolean?
) → State<T>,
get(selfState<T>) → T,
hook(
selfState<T>,
callbackFunction
) → Function,
Destroy(selfState<T>) → (),
bindToProperty(
selfState<T>,
instanceInstancepropertystring
) → (),
bindToAttribute(
selfState<T>,
instanceInstance,
attributestring
) → ()
}

Represents a reactive state object in the Flux system

Stateful<T>

type Stateful<T> = T | State<T>

A type for state or raw values

SpecialKey

type SpecialKey = {type"SpecialKey"}

A type for state or raw values

SpecialDefinition

type SpecialDefinition = {[number | string | SpecialKey]unknown}

Represents the definition used in Flux.new and Flux.edit

Scope

type Scope = {[any]=Scope | any}

Properties

Scope

Flux.Scope: Scope

A scope object for organizing and cleaning up Flux states

Attribute

This item is read only and cannot be modified. Read Only
Flux.Attribute: SpecialKey

A marker for defining Instance attributes in Flux.edit

Children

This item is read only and cannot be modified. Read Only
Flux.Children: SpecialKey

A marker for defining Instance children in Flux.edit

Event

This item is read only and cannot be modified. Read Only
Flux.Event: SpecialKey&{
Attribute=SpecialKey,
Property=SpecialKey
}

Markers for defining events in Flux.edit

Functions

isState

Flux.isState(objectany) → boolean

Checks if an object is a Flux state

peek

Flux.peek(objectT) → T

Gets the current value of a Flux state or returns the input if it's not a state

peekVariadic

Flux.peekVariadic(...any) → ...any

Gets the current values of multiple Flux states or non-state inputs

edit

Flux.edit(
instanceInstance,
) → Instance

Edits an existing Instance with Flux state bindings and other properties

new

Flux.new(classNamestring) → Flux.edit

Creates a new Instance with Flux state bindings and other properties

computeFrom

Flux.computeFrom(
computation(...any) → T,
...any
) → State<T>

Creates a computed state based on other states or static values

compute

Flux.compute(computation(use<U>(U | State<U>) → U?) → T) → State<T>

Creates a computed state, passing a use function to access and bind other states

tween

Flux.tween(
tweenInfoStateful<TweenInfo>,
stateState<T>
) → State<T>

Applies TweenService tweens with Instance properties bound to the Flux state

state

Flux.state(
initialValueT | State<T> | Instance,
propertystring?
) → State<T>

Creates a new Flux state with an initial value

_addDependency

Flux:_addDependency(dependencyState<T>) → ()

Adds a dependency to the current state

_removeDependency

Flux:_removeDependency(dependencyState<T>) → ()

Removes a dependency from the current state

_update

Flux:_update(noTweenboolean?) → ()

Updates the state and propagates changes to dependents

Destroy

Flux:Destroy() → ()

Destroys the state, clearing all dependencies and bindings

hook

Flux:hook(callbackFunction) → Function

Adds a hook callback function to be called when the state changes

get

Flux:get() → any

Gets the current value of the state

set

Flux:set(
newT,
forceUpdateboolean?,
noTweenboolean?
) → State<T>

Sets a new value for the state and triggers an update

bindToProperty

Flux:bindToProperty(
instanceInstance,
propertystring
) → ()

Binds the state to a property of an Instance

bindToAttribute

Flux:bindToAttribute(
instanceInstance,
attributestring
) → ()

Binds the state to an attribute of an Instance

Show raw api
{
    "functions": [
        {
            "name": "isState",
            "desc": "Checks if an object is a Flux state",
            "params": [
                {
                    "name": "object",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 68,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "peek",
            "desc": "Gets the current value of a Flux state or returns the input if it's not a state",
            "params": [
                {
                    "name": "object",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 74,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "peekVariadic",
            "desc": "Gets the current values of multiple Flux states or non-state inputs",
            "params": [
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "...any\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 80,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "_addDependency",
            "desc": "Adds a dependency to the current state",
            "params": [
                {
                    "name": "dependency",
                    "desc": "",
                    "lua_type": "State<T>"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 193,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "_removeDependency",
            "desc": "Removes a dependency from the current state",
            "params": [
                {
                    "name": "dependency",
                    "desc": "",
                    "lua_type": "State<T>"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 202,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "_update",
            "desc": "Updates the state and propagates changes to dependents",
            "params": [
                {
                    "name": "noTween",
                    "desc": "",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 216,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Destroys the state, clearing all dependencies and bindings",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 263,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "hook",
            "desc": "Adds a hook callback function to be called when the state changes",
            "params": [
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "Function"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Function\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 285,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "get",
            "desc": "Gets the current value of the state",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "any\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 296,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "set",
            "desc": "Sets a new value for the state and triggers an update",
            "params": [
                {
                    "name": "new",
                    "desc": "",
                    "lua_type": "T"
                },
                {
                    "name": "forceUpdate",
                    "desc": "",
                    "lua_type": "boolean?"
                },
                {
                    "name": "noTween",
                    "desc": "",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "State<T>\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 301,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "bindToProperty",
            "desc": "Binds the state to a property of an Instance",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "property",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 312,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "bindToAttribute",
            "desc": "Binds the state to an attribute of an Instance",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "attribute",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 329,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "edit",
            "desc": "Edits an existing Instance with Flux state bindings and other properties",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "definition",
                    "desc": "",
                    "lua_type": "SpecialDefinition & Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Instance\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 393,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "new",
            "desc": "Creates a new Instance with Flux state bindings and other properties",
            "params": [
                {
                    "name": "className",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Flux.edit"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 496,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "computeFrom",
            "desc": "Creates a computed state based on other states or static values",
            "params": [
                {
                    "name": "computation",
                    "desc": "",
                    "lua_type": "(...any) -> T"
                },
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "State<T>\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 503,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "compute",
            "desc": "Creates a computed state, passing a use function to access and bind other states",
            "params": [
                {
                    "name": "computation",
                    "desc": "",
                    "lua_type": "(use: <U>(U | State<U>) -> U?) -> T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "State<T>\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 517,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "tween",
            "desc": "Applies TweenService tweens with Instance properties bound to the Flux state",
            "params": [
                {
                    "name": "tweenInfo",
                    "desc": "",
                    "lua_type": "Stateful<TweenInfo>"
                },
                {
                    "name": "state",
                    "desc": "",
                    "lua_type": "State<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "State<T>\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 532,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "state",
            "desc": "Creates a new Flux state with an initial value",
            "params": [
                {
                    "name": "initialValue",
                    "desc": "",
                    "lua_type": "T | State<T> | Instance"
                },
                {
                    "name": "property",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "State<T>\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 541,
                "path": "MainModule/Flux.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "Scope",
            "desc": "A scope object for organizing and cleaning up Flux states",
            "lua_type": "Scope",
            "source": {
                "line": 172,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "Attribute",
            "desc": "A marker for defining Instance attributes in [Flux.edit]",
            "lua_type": "SpecialKey",
            "readonly": true,
            "source": {
                "line": 178,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "Children",
            "desc": "A marker for defining Instance children in [Flux.edit]",
            "lua_type": "SpecialKey",
            "readonly": true,
            "source": {
                "line": 184,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "Event",
            "desc": "Markers for defining events in [Flux.edit]",
            "lua_type": "SpecialKey & { Attribute = SpecialKey, Property = SpecialKey }",
            "readonly": true,
            "source": {
                "line": 190,
                "path": "MainModule/Flux.luau"
            }
        }
    ],
    "types": [
        {
            "name": "Function",
            "desc": "A generic function type",
            "lua_type": "(...any) -> ...any",
            "source": {
                "line": 4,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "List",
            "desc": "A generic list type",
            "lua_type": "{ T }",
            "source": {
                "line": 9,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "Set",
            "desc": "A generic set type implemented as a table with boolean values",
            "lua_type": "{ [T]: boolean }",
            "source": {
                "line": 14,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "Dict",
            "desc": "Represents a dictionary-like table with keys of type `T` and values of any type.",
            "lua_type": "{ [T]: any }",
            "source": {
                "line": 19,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "State",
            "desc": "Represents a reactive state object in the Flux system",
            "lua_type": "{ _update: (State<T>) -> boolean, _dependencies: Set<State<T>>, _dependents: Set<State<T>>, _binds: { [T]: any, _cleanup: List<any> }, _hooks: Dict<Function>, _value: T, _stateful: boolean, _operation: List<any>?, _tweenInfo: TweenInfo | any, set: (self: State<T>, new: T, force: boolean?, noTween: boolean?) -> State<T>, get: (self: State<T>) -> T, hook: (self: State<T>, callback: Function) -> Function, Destroy: (self: State<T>) -> (), bindToProperty: (self: State<T>, instance: Instanceproperty: string) -> (), bindToAttribute: (self: State<T>, instance: Instance, attribute: string) -> () }",
            "source": {
                "line": 26,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "Stateful<T>",
            "desc": "A type for state or raw values",
            "lua_type": "T | State<T>",
            "source": {
                "line": 47,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "SpecialKey",
            "desc": "A type for state or raw values",
            "lua_type": "{ type: \"SpecialKey\" }",
            "source": {
                "line": 52,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "SpecialDefinition",
            "desc": "Represents the definition used in [Flux.new] and [Flux.edit]",
            "lua_type": "{ [number | string | SpecialKey]: unknown }",
            "source": {
                "line": 59,
                "path": "MainModule/Flux.luau"
            }
        },
        {
            "name": "Scope",
            "desc": "",
            "lua_type": "{[any] = Scope | any}",
            "source": {
                "line": 155,
                "path": "MainModule/Flux.luau"
            }
        }
    ],
    "name": "Flux",
    "desc": "A library for easily creating and managing reactive state.",
    "source": {
        "line": 132,
        "path": "MainModule/Flux.luau"
    }
}