alien_signals library

Signals, computed values, and effects for reactive state.

Start with signal and computed, observe changes with effect, and call the returned effect handle when its work is no longer needed. Use effectScope to group lifetimes and startBatch to group writes.

final count = signal(0);
final doubled = computed((_) => count() * 2);

final stop = effect(() {
  print('Count: ${count()}, Doubled: ${doubled()}');
}); // Count: 0, Doubled: 0

count.set(1); // Count: 1, Doubled: 2
stop();
count.set(2); // The stopped effect no longer runs.

Classes

Computed<T>
A cached, read-only value derived from other signals.
Effect
A side effect that tracks synchronous reads of reactive values.
EffectScope
A group of effects and nested scopes with a shared lifetime.
Signal<T>
A reactive value of type T.
WritableSignal<T>
A reactive value that can be read and written.

Functions

computed<T>(T getter(T?)) → Computed<T>
Creates a cached value derived by getter from other signals.
effect<T>(EffectCallback<T> fn) → Effect
Runs fn immediately and again when its tracked dependencies change.
effectScope(void fn()) → EffectScope
Runs fn in a scope that groups effects for disposal.
endBatch() → void
Ends a batch started by startBatch.
signal<T>(T initialValue) → WritableSignal<T>
Creates a writable signal containing initialValue.
startBatch() → void
Starts a batch that defers effect execution until endBatch.
trigger(void fn()) → void
Notifies subscribers of the signals read synchronously by fn.

Typedefs

EffectCallback<T> = T Function()
Callback passed to an effect.
EffectCleanup = void Function()
Cleanup function returned by an effect callback.