Skip to content

Conditional ​

Control flow, list mapping, and keyed selection helpers (show, showKeyed, switch, presence, pick, fallback, forValue, forIndex, selector).

luau
Flux.show(loggedIn, function() return Profile {} end, function() return SignIn {} end)

Types ​

Selector type ​

luau
type Selector<K> = setmetatable<{
	--[[
	Reactively reads whether `key` matches the selector's source.
	[Open Documentation](https://flux.kohl.gg/guide/concepts/selectors#reading-a-selection)
	]]
	get: (self: any, key: K) -> boolean,
	--[[
	Destroys the selector and disposes its internal watcher and per-key nodes.
	[Open Documentation](https://flux.kohl.gg/guide/concepts/selectors#cleaning-up)
	]]
	Destroy: (self: any) -> (),
}, { __call: (self: any, key: K) -> boolean }>

Properties ​

otherwise Read Only ​

luau
Conditional.otherwise: any

Catch-all branch key for Flux.switch maps when source matches no explicit key.

luau
Flux.switch(state) {
	loading = function() return Spinner {} end,
	[Flux.otherwise] = function(value) return Label { text = value } end,
}

Open Documentation

Functions ​

show ​

luau
Conditional.show<T, F>(condition: unknown, component: (value: () -> any) -> T, fallback: ((value: () -> any) -> F)?): Node<T | F>

Mounts component while condition is truthy, or fallback when falsy, in its own child scope. Rebuilds only when truthiness flips (use Flux.showKeyed to rebuild on every identity change).

Open Documentation

showKeyed ​

luau
Conditional.showKeyed<T, F>(condition: unknown, component: (value: () -> any) -> T, fallback: ((value: () -> any) -> F)?): Node<T | F>

Mounts component while condition is truthy (or fallback when falsy) and remounts in a fresh scope whenever condition changes identity.

Open Documentation

switch ​

luau
Conditional.switch<S>(source: S)

Mounts the branch factory matching source's current value in its own child scope. Use [Flux.otherwise] in map as a catch-all branch for unmatched values.

Open Documentation

presence ​

luau
Conditional.presence<T>(condition: unknown, component: (exiting: Node<boolean>, done: () -> ()) -> T): Node<T?>

Mounts component(exiting, done) while condition is truthy and keeps it mounted while exiting() is true until done() is called. If condition turns truthy again before done() runs, exiting flips back to false without remounting.

Open Documentation

pick ​

luau
Conditional.pick(condition: unknown, whenTrue: any, whenFalse: any?): Node<any>

Derives a node returning whenTrue while condition is truthy and whenFalse otherwise. Only the active branch is read, and no branch scope is created.

Open Documentation

fallback ​

luau
Conditional.fallback<V, D>(value: V, default: D): Node<NonNil<Graph.Unwrap<V>> | Graph.Unwrap<D>>

Derives a node returning value when non-nil, or default when value is nil. Preserves false instead of replacing it like or.

Open Documentation

forIndex ​

luau
Conditional.forIndex<L, U>(list: L, mapFn: (index: number, item: Node<Item<L>>) -> U): Node<{ U }>

Maps list by numeric index, running mapFn(index, item) once per slot and updating item in place when the value at that index changes.

Open Documentation

forValue ​

luau
Conditional.forValue<L, U>(list: L, mapFn: (index: Node<number>, value: Item<L>) -> U): Node<{ U }>

Maps list by item identity, running mapFn(index, value) once per unique value and updating index when an item moves. Values must be unique (use Flux.forIndex for primitive or duplicate values).

Open Documentation

selector ​

luau
Conditional.selector<S, K>(source: S, equals: ((sourceValue: Graph.Unwrap<S>, key: K) -> boolean)?): Selector<K>

Creates a keyed selector that tracks which key matches source in O(1) (or O(observed keys) with a custom equals comparator).

Open Documentation

Selector ​

Constructors: Conditional.selector

get ​

luau
Selector:get(key: any): boolean

Reactively reads whether key matches the selector's source.

Open Documentation

Destroy ​

luau
Selector:Destroy()

Destroys the selector and disposes its internal watcher and per-key nodes.

Open Documentation