Skip to content

AIDK API Reference / aidk/state

aidk/state ​

AIDK State ​

Reactive state management for AIDK components. Provides a signals-based system similar to SolidJS/Angular signals with fine-grained reactivity.

Features ​

  • Signals - Reactive primitives for fine-grained state updates
  • Computed - Derived values that auto-recompute when dependencies change
  • Effects - Side-effects that re-run on dependency changes
  • COM State - Shared state bound to Context Object Model
  • Batching - Multiple updates trigger effects only once

Quick Start ​

typescript
import { signal, computed, effect, batch } from 'aidk';

// Create a signal
const count = signal(0);

// Read and write
console.log(count.value); // 0
count.value = 1;

// Computed values
const doubled = computed(() => count.value * 2);
console.log(doubled.value); // 2

// Effects run on changes
effect(() => {
  console.log(`Count is: ${count.value}`);
});

// Batch multiple updates
batch(() => {
  count.value = 2;
  count.value = 3;
}); // Effect runs once with value 3

In Components ​

tsx
class Counter extends Component {
  count = signal(0);

  onMount() {
    effect(() => {
      console.log(`Count: ${this.count.value}`);
    });
  }

  render() {
    return <User>Current count: {this.count.value}</User>;
  }
}

See ​

Interfaces ​

InterfaceDescription
ComputedSignalRead the current value
EffectRef-
ReadonlySignalA read-only signal that can be observed but not modified. Used for watching state owned by another component.
SignalRead the current value
SignalOptions-

Variables ​

VariableDescription
COM_SIGNAL_SYMBOL-
COMPUTED_SYMBOL-
EFFECT_SYMBOL-
PROPS_SIGNAL_SYMBOL-
REQUIRED_INPUT_SYMBOL-
SIGNAL_SYMBOL-
WATCH_SIGNAL_SYMBOL-

Functions ​

FunctionDescription
batchBatch multiple signal updates together. Effects only run once after all updates complete.
bindCOMSignalsBinds all COM signals on a component instance. Called automatically in EngineComponent.onMount().
cleanupSignalsCleans up all signals on a component instance. Called automatically in EngineComponent.onUnmount().
computedCreates a computed signal that derives its value from other signals. Computed values are memoized and only recompute when dependencies change.
comStateCreates a COM-bound signal (shared state).
disposeSignalManually dispose a single signal. Use when you need to clean up a signal before component unmount.
effectRuns an effect that automatically re-runs when dependencies change. Use sparingly - prefer computed() for derived values.
getCurrentContextGet current render context. Throws if called outside render.
getCurrentFiberGet current fiber (for advanced use).
inputCreates a signal bound to a component prop.
isComputedCheck if a value is a computed signal.
isEffectCheck if a value is an effect ref.
isSignalCheck if a value is a signal.
setRenderContextSet render context (called by compiler).
setScheduleWork-
signalCreates a writable signal with an initial value.
untrackedRead a signal without tracking it as a dependency. Useful when you want to read a value in a computed/effect without triggering re-runs when that value changes.
useAbortSignaluseAbortSignal - Get abort signal for current execution.
useAfterCompileuseAfterCompile - Run after compile, can request recompile.
useAsyncuseAsync - Async data fetching.
useCallbackuseCallback - Memoize callback function.
useComputeduseComputed - Create a reactive computed signal that persists across renders.
useCOMRefuseCOMRef - Get component ref from COM.
useComStateuseComState - COM-bound shared state.
useCounteruseCounter - Numeric counter.
useDebugValueuseDebugValue - Display value in devtools (no-op in production).
useEffectuseEffect - Side effect after commit.
useInituseInit - Component initialization that runs once on mount. Can be async and should be awaited if it returns a Promise. Runs DURING render, blocking until complete.
useInputuseInput - Reactive prop access with default value.
useMemouseMemo - Memoize expensive computation.
useOnMessageuseOnMessage - Handle execution messages.
useOnMountuseOnMount - Run once when component mounts as a side effect. Runs AFTER render (as an effect), does not block rendering. Use for non-critical side effects like logging, analytics.
useOnUnmountuseOnUnmount - Run once when component unmounts.
usePrevioususePrevious - Track previous value.
useReduceruseReducer - State with reducer pattern.
useRefuseRef - Mutable ref that persists across renders.
useSignaluseSignal - Signal-based state in function components.
useStateuseState - Local component state.
useTickEnduseTickEnd - Run at end of each tick, after model execution.
useTickStartuseTickStart - Run at start of each tick, before render.
useToggleuseToggle - Boolean toggle state.
useWatchuseWatch - Read-only COM state observation. Returns a ReadonlySignal for reactive access to the watched state.
watchShorthand for watchComState - creates a read-only signal watching COM state.
watchComStateCreates a read-only signal that watches COM state.

Released under the MIT License.