Skip to main content
cngx-src documentation

SelectionController

Interface

projects/core/utils/selection-controller.ts

Import#

import { SelectionController } from '@cngx/core/utils'

Description#

Signal-based selection engine. Reads + writes an external WritableSignal<T[]> — does not own the values.

Memoizes per-value isSelected / isIndeterminate signals by key so template diff stays stable and consumers can pass the handle into child components without identity churn.

Index#

Instance Properties#

hasSelection#Signal
Readonly

true when at least one value is selected.

isEmpty#Signal
Readonly

true when nothing is selected.

selected#Signal
Readonly

Snapshot of currently selected values (structural-equality computed).

selectedCount#Signal
Readonly

Current selection size.

Methods#

clear#void

Clear selection.

deselect#void
deselect(value: T)

Remove from selection. No-op if not selected.

@paramvalueT
destroy#void

Release retained per-value signal caches. Post-destroy isSelected(v) / isIndeterminate(v) return a shared Signal<false> no-op (identity-stable across all calls) so existing bindings keep working without further memory retention. Writes (select, deselect, toggle, toggleAll, clear, set) still mutate values but do not repopulate the caches. Idempotent.

isIndeterminate#Signal
isIndeterminate(value: T)

Reactive indeterminate state. With childrenFn: true iff SOME but not ALL descendants are selected. Without: always returns a shared constant Signal<false>.

@paramvalueT
isSelected#Signal
isSelected(value: T)

Reactive membership for a single value. Same value (by keyFn) always returns the SAME Signal instance — safe to pass into OnPush children or compare with ===.

@paramvalueT
select#void
select(value: T)

Idempotent add. No-op if already selected.

@paramvalueT
set(values: unknown)

Replace selection with the given values (copied).

@paramvaluesunknown
toggle#void
toggle(value: T)

Toggle a single value.

@paramvalueT
toggleAll#void
toggleAll(values: unknown)

Toggle-all semantics over a group: if every value in values is already selected, remove them all; otherwise add the missing ones.

@paramvaluesunknown