KStateContainer

The StateContainer implementation for Kotlin components. Tracks all state defined by useState calls for the same component (see KState for usage). Immutable by default: every copy-on-write mutation returns a new instance with the prior entries copied and one entry added or replaced. The one exception is the transient render-owned fork (mutableForkWith / mutateInPlace): a render forks a single mutable copy of its component's container and then mutates that copy in place for the rest of the pass, tracked by ComponentScope.ownedStateContainer. Committed/shared containers are never mutated in place - a subsequent render forks them.

Each entry carries its HookKey; lookup is an O(N) linear scan over the list using HookKey equality via getByHookKey/hasHookKey/copyAndMutateByHookKey. Interning lets equality short-circuit on reference identity, so the scan is essentially a pointer compare.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Hosts API to debug state

Link copied to clipboard

Functions

Link copied to clipboard
open override fun applyStateUpdate(stateUpdate: StateContainer.StateUpdate)
Link copied to clipboard
open override fun clone(): StateContainer
Link copied to clipboard

Add or replace the entry for hookKey, preserving its existing CachedValue.deps when one is already present (and using NoDeps otherwise).

fun copyAndMutateByHookKey(hookKey: HookKey, newValue: Any?, deps: Array<*>): KStateContainer

Add or replace the entry for hookKey; deps overwrites any previously stored deps.

Link copied to clipboard
Link copied to clipboard
fun hasHookKey(hookKey: HookKey): Boolean
Link copied to clipboard
fun mutableForkWith(hookKey: HookKey, newValue: Any?, deps: Array<*>?): KStateContainer

Fork a single mutable copy of this container with hookKey added or replaced. The returned container's backing is a live ArrayList (not wrapped), so the owning render can keep mutating it in place via mutateInPlace for the rest of the pass. The caller (KState) records the result as ComponentScope.ownedStateContainer so subsequent mutations this pass route to mutateInPlace.

Link copied to clipboard
fun mutateInPlace(hookKey: HookKey, newValue: Any?, deps: Array<*>?): KStateContainer

Mutate this container in place. MUST ONLY be done by a scope that owns this container for its current render pass (tracked by ComponentScope.ownedStateContainer); the caller guarantees that with an identity check.

Link copied to clipboard

Return a container with only the entries whose CachedValue.hookKey is in live (null-hookKey index entries are always kept). Returns this when nothing is dropped.

Link copied to clipboard
open override fun toString(): String