Skip to content

State

A single reactive value, and the listeners watching it.

Constructors: Flux.state · State.new

Types

State type

luau
type State<T> = typeof(setmetatable(
	{} :: {
		value: T, -- the value the state currently holds
		listeners: { (T) -> () }, -- everything registered through [State:Connect]
	},
	State
))

A value that notifies listeners whenever it changes.

Functions

new

luau
State.new<T>(initial: T?): State<T>

Creates a state holding initial.

isState

luau
State.isState(value: any): boolean

Reports whether value is a state.

Methods

Connect

luau
State:Connect(callback: (any) -> ()): () -> ()

Runs callback whenever the value changes.

Returns a function that disconnects the listener again.

Destroy Deprecated since 2.0

DEPRECATED

states are collected once nothing references them

luau
State:Destroy()

Drops every listener and releases the state.