Conditional
Control flow, list mapping, and keyed selection helpers (show, showKeyed, switch, presence, pick, fallback, forValue, forIndex, selector).
Flux.show(loggedIn, function() return Profile {} end, function() return SignIn {} end)Types
Selector type
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
Conditional.otherwise: anyCatch-all branch key for Flux.switch maps when source matches no explicit key.
Flux.switch(state) {
loading = function() return Spinner {} end,
[Flux.otherwise] = function(value) return Label { text = value } end,
}Functions
show
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).
showKeyed
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.
switch
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.
presence
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.
pick
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.
fallback
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.
forIndex
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.
forValue
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).
selector
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).
Selector
Constructors: Conditional.selector
get
Selector:get(key: any): booleanReactively reads whether key matches the selector's source.
Destroy
Selector:Destroy()Destroys the selector and disposes its internal watcher and per-key nodes.