Manages the current reactive subscriber context.
This class provides the infrastructure for automatic dependency tracking in Lark's reactivity system. It maintains a stack of active subscribers, allowing nested reactive computations.
Usage
Typically, you don't interact with ReactiveScope directly. The Computed and Effect classes manage scopes internally. However, understanding the API helps with debugging and advanced use cases.
Running with a Subscriber Context
final subscriber = MySubscriber();
final result = ReactiveScope.run(subscriber, () {
// Any refs read here will register 'subscriber' as dependent
return someRef.value + anotherRef.value;
});
Checking the Current Context
void onRefRead() {
final current = ReactiveScope.current;
if (current != null) {
// We're inside a tracked computation
registerSubscriber(current);
}
}
Opting Out of Tracking
effect(() {
final tracked = someRef(); // Tracked
final untracked = ReactiveScope.untrack(() {
return otherRef(); // NOT tracked
});
});
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- current → Subscriber?
-
Gets the currently active subscriber, if any.
no setter
- depth → int
-
The current nesting depth of reactive scopes.
no setter
- isTracking → bool
-
Whether we're currently inside a tracked reactive scope.
no setter
Static Methods
-
debugSnapshot(
) → Map< String, dynamic> - Creates a snapshot of the current scope state for debugging.
-
reset(
) → void - Resets the scope stack to empty.
-
run<
T> (Subscriber? subscriber, T fn()) → T - Runs a function with the given subscriber as the current context.
-
untrack<
T> (T fn()) → T - Runs a function without tracking any dependencies.