Skip to content

Selector

Types

Selector type

luau
type Selector<K> = {
	get: (self: Selector<K>, key: K) -> boolean,
	destroy: (self: Selector<K>) -> (),
	_nodes: { [any]: Graph.Node<boolean> },
	_watcher: Graph.Node<any>,
	_equals: ((sourceValue: any, key: K) -> boolean)?,
	_active: any,
}

Functions

new

luau
Selector.new<S, K>(source: Graph.Node<S> | (() -> S) | S, equals: ((sourceValue: S, key: K) -> boolean)?): Selector<K>

Creates an O(1) keyed selector for efficiently tracking which of many keys matches a single selected value: selecting a row, a tab, or a focused item. The returned object is callable: selector(key) reactively reads whether key is selected, so flipping the selection re-runs only the two affected keys instead of every observer.

Open Documentation

Parameters

  • source: The tracked selection: a node, a () -> S computed, or a plain value.
  • equals: Tests the source value against a key (default ==). The default path flips at most two per-key nodes per change (O(1)); a custom comparator re-tests every live key per change (O(live keys)).