redus library

Redus - Developer utilities for convenience and performance.

This is the main entry point for the redus package. For specific modules, import them directly:

  • package:redus/reactivity.dart for fine-grained reactivity
  • package:redus/di.dart for dependency injection

Classes

Computed<T>
A computed reactive value.
EffectScope
An effect scope for grouping and disposing reactive effects.
ReactiveEffect
Represents a reactive side effect that re-runs when dependencies change.
Readonly<T>
A readonly wrapper around a reactive value.
Ref<T>
A reactive reference container.
Scheduler
Scheduler for batching and flushing effects.
ServiceLocator
Service locator for dependency injection.
ShallowReadonly<T>
A shallow readonly wrapper.
ShallowRef<T>
A shallow reactive reference.
WatchHandle
Handle to control a watcher.
WatchOptions
Options for configuring watch behavior.
WritableComputed<T>
A writable computed value.

Enums

FlushMode
Flush timing for effects.

Extensions

ReadonlyComputed on Computed<T>
Extension to create readonly from Computed.
ReadonlyRef on Ref<T>
Extension to create readonly from Ref.
ScopedEffect on ReactiveEffect
Extension to register effects with the current scope.

Properties

activeEffect ReactiveEffect?
The currently active effect being executed.
getter/setter pair
effectStack List<ReactiveEffect>
Stack of active effects for nested effect handling.
final

Functions

computed<T>(T getter()) Computed<T>
Creates a readonly computed value.
customRef<T>(CustomRefFactory<T> factory) Ref<T>
Creates a customized ref with explicit control over dependency tracking.
effectScope({bool detached = false}) EffectScope
Creates an effect scope for grouping reactive effects.
get<T extends Object>({Symbol? key}) → T
Get a registered instance or factory result.
getCurrentScope() EffectScope?
Get the currently active effect scope.
isMarkedRaw(Object? value) bool
Check if an object is marked as raw.
isProxy(Object? value) bool
Check if a value is a reactive proxy (Ref, Computed, Readonly, ShallowRef).
isReactive(Object? value) bool
Check if a value is reactive (Ref, Computed, or ShallowRef).
isReadonly(Object? value) bool
Check if a value is readonly (Readonly or read-only Computed).
isRef(Object? value) bool
Check if a value is a Ref.
isRegistered<T extends Object>({Symbol? key}) bool
Check if a type (and optional key) is registered.
markRaw<T extends Object>(T value) → T
Marks an object so that it will never be converted to a reactive proxy.
onScopeDispose(void callback(), {bool failSilently = false}) → void
Register a dispose callback on the current active effect scope.
onWatcherCleanup(CleanupFn cleanup, {bool failSilently = false}) → void
Register a cleanup function for the current watcher.
readonly<T>(Object source) Readonly<T>
Creates a readonly proxy of a reactive value.
ref<T>(T value) Ref<T>
Creates a reactive reference to a value.
register<T extends Object>(T instance, {Symbol? key}) → void
Register a singleton instance.
registerFactory<T extends Object>(T factory(), {Symbol? key}) → void
Register a factory function.
resetLocator() → void
Reset all registrations.
shallowReadonly<T>(Object source) ShallowReadonly<T>
Creates a shallow readonly wrapper.
shallowRef<T>(T value) ShallowRef<T>
Creates a shallow ref - only .value access is reactive.
toRaw<T>(Object? value) → T
Returns the raw, original value from a reactive wrapper.
toRef<T>(Object source) Ref<T>
Normalizes value/ref/getter to a Ref.
toRefs<T>(Map<String, T> source) Map<String, Ref<T>>
Converts a Map to a Map of Refs.
toValue<T>(Object source) → T
Normalizes values/refs/getters to values.
triggerRef(ShallowRef ref) → void
Force trigger effects that depend on a shallow ref.
unref<T>(Object? maybeRef) → T
Unwrap a Ref to get its value, or return the value as-is if not a Ref.
unregister<T extends Object>({Symbol? key}) → void
Remove a registered instance or factory.
watch<T>(T source(), WatchCallback<T> callback, {WatchOptions options = WatchOptions.defaults}) WatchHandle
Watches a reactive source and invokes a callback when it changes.
watchEffect(EffectFn effect, {WatchOptions options = WatchOptions.defaults}) WatchHandle
Runs an effect immediately and re-runs it when dependencies change.
watchMultiple<T>(List<T Function()> sources, void callback(List<T> values, List<T?> oldValues, OnCleanup onCleanup), {WatchOptions options = WatchOptions.defaults}) WatchHandle
Watches multiple sources and invokes callback when any of them change.
watchPostEffect(EffectFn effect) WatchHandle
Alias for watchEffect with flush: FlushMode.post.
watchSyncEffect(EffectFn effect) WatchHandle
Alias for watchEffect with flush: FlushMode.sync.
writableComputed<T>({required T get(), required void set(T value)}) WritableComputed<T>
Creates a writable computed value.

Typedefs

CleanupFn = void Function()
Effect cleanup function type.
CustomRefFactory<T> = ({T Function() get, void Function(T) set}) Function(void track(), void trigger())
Factory function for creating a custom ref.
EffectFn = void Function(OnCleanup onCleanup)
Watch effect function signature.
OnCleanup = void Function(CleanupFn cleanup)
Callback for registering cleanup in effects.
WatchCallback<T> = void Function(T value, T? oldValue, OnCleanup onCleanup)
Watch callback signature with new value, old value, and cleanup registration.
WatchGetter<T> = T Function()
Getter function for watch sources.