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 3In 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 ​
| Interface | Description |
|---|---|
| ComputedSignal | Read the current value |
| EffectRef | - |
| ReadonlySignal | A read-only signal that can be observed but not modified. Used for watching state owned by another component. |
| Signal | Read the current value |
| SignalOptions | - |
Variables ​
| Variable | Description |
|---|---|
| COM_SIGNAL_SYMBOL | - |
| COMPUTED_SYMBOL | - |
| EFFECT_SYMBOL | - |
| PROPS_SIGNAL_SYMBOL | - |
| REQUIRED_INPUT_SYMBOL | - |
| SIGNAL_SYMBOL | - |
| WATCH_SIGNAL_SYMBOL | - |
Functions ​
| Function | Description |
|---|---|
| batch | Batch multiple signal updates together. Effects only run once after all updates complete. |
| bindCOMSignals | Binds all COM signals on a component instance. Called automatically in EngineComponent.onMount(). |
| cleanupSignals | Cleans up all signals on a component instance. Called automatically in EngineComponent.onUnmount(). |
| computed | Creates a computed signal that derives its value from other signals. Computed values are memoized and only recompute when dependencies change. |
| comState | Creates a COM-bound signal (shared state). |
| disposeSignal | Manually dispose a single signal. Use when you need to clean up a signal before component unmount. |
| effect | Runs an effect that automatically re-runs when dependencies change. Use sparingly - prefer computed() for derived values. |
| getCurrentContext | Get current render context. Throws if called outside render. |
| getCurrentFiber | Get current fiber (for advanced use). |
| input | Creates a signal bound to a component prop. |
| isComputed | Check if a value is a computed signal. |
| isEffect | Check if a value is an effect ref. |
| isSignal | Check if a value is a signal. |
| setRenderContext | Set render context (called by compiler). |
| setScheduleWork | - |
| signal | Creates a writable signal with an initial value. |
| untracked | Read 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. |
| useAbortSignal | useAbortSignal - Get abort signal for current execution. |
| useAfterCompile | useAfterCompile - Run after compile, can request recompile. |
| useAsync | useAsync - Async data fetching. |
| useCallback | useCallback - Memoize callback function. |
| useComputed | useComputed - Create a reactive computed signal that persists across renders. |
| useCOMRef | useCOMRef - Get component ref from COM. |
| useComState | useComState - COM-bound shared state. |
| useCounter | useCounter - Numeric counter. |
| useDebugValue | useDebugValue - Display value in devtools (no-op in production). |
| useEffect | useEffect - Side effect after commit. |
| useInit | useInit - 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. |
| useInput | useInput - Reactive prop access with default value. |
| useMemo | useMemo - Memoize expensive computation. |
| useOnMessage | useOnMessage - Handle execution messages. |
| useOnMount | useOnMount - 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. |
| useOnUnmount | useOnUnmount - Run once when component unmounts. |
| usePrevious | usePrevious - Track previous value. |
| useReducer | useReducer - State with reducer pattern. |
| useRef | useRef - Mutable ref that persists across renders. |
| useSignal | useSignal - Signal-based state in function components. |
| useState - Local component state. | |
| useTickEnd | useTickEnd - Run at end of each tick, after model execution. |
| useTickStart | useTickStart - Run at start of each tick, before render. |
| useToggle | useToggle - Boolean toggle state. |
| useWatch | useWatch - Read-only COM state observation. Returns a ReadonlySignal for reactive access to the watched state. |
| watch | Shorthand for watchComState - creates a read-only signal watching COM state. |
| watchComState | Creates a read-only signal that watches COM state. |