@stateloom/core
v1.0.0-alpha.0
Published
The reactive kernel for StateLoom. Provides the primitive building blocks that every other `@stateloom/*` package builds on.
Readme
@stateloom/core
The reactive kernel for StateLoom. Provides the primitive building blocks that every other @stateloom/* package builds on.
Install
pnpm add @stateloom/coreQuick Start
import { signal, computed, effect, batch } from '@stateloom/core';
const count = signal(0);
const doubled = computed(() => count.get() * 2);
const dispose = effect(() => {
console.log(`count=${count.get()}, doubled=${doubled.get()}`);
return undefined;
});
// "count=0, doubled=0"
batch(() => {
count.set(5);
count.update((n) => n + 1);
});
// "count=6, doubled=12" — fires once
dispose();Exports
| Export | Description |
| ----------------------- | ---------------------------------------------- |
| signal(value) | Mutable reactive value container |
| computed(fn) | Lazy, memoized derived value |
| effect(fn) | Auto-tracking side effect with cleanup |
| batch(fn) | Coalesce multiple writes into one notification |
| createScope() | SSR isolation scope |
| runInScope(scope, fn) | Execute code within a scope |
| serializeScope(scope) | Serialize scope state for hydration |
Types
Subscribable<T>, Signal<T>, ReadonlySignal<T>, SignalOptions<T>, Scope
Size
~1.5 KB gzipped
