JObserver class
JObserver is a centralized observability utility to track lifecycle events in the JIntent architecture.
There are two ways to listen:
- addObserver registers a JObserverDelegate. Several observers can be registered at once and each registration can be removed on its own.
- The static
on...callbacks hold a single slot each; assigning one replaces the previous value. They keep working and are invoked before the registered observers.
Observer failures never reach the code being observed: they are reported through FlutterError.reportError and the remaining observers still run. Notifications are global; call reset in tests that register observers.
Constructors
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
- onEffectEmitted ↔ void Function(JEffect effect)?
-
Callback triggered when a side effect is emitted.
getter/setter pair
-
onIntentDispatched
↔ void Function(JIntent<
JState> intent)? -
Callback triggered when an intent is dispatched and completed. Cancelled
and dropped intents are reported only to observers
(JObserverDelegate.onIntentCancelled, JObserverDelegate.onIntentDropped).
getter/setter pair
-
onIntentFailed
↔ void Function(JIntent<
JState> intent, Object error, StackTrace stackTrace)? -
Callback triggered when an intent fails while executing.
getter/setter pair
-
onStateChanged
↔ void Function(JState prev, JState next, JIntent<
JState> ? origin)? -
Callback triggered when state changes from
prevtonext. Optionally includes the originating intent.getter/setter pair
Static Methods
-
addObserver(
JObserverDelegate observer) → void Function() -
Registers
observerand returns a function that removes it. -
notifyEffectEmitted(
JEffect effect) → void - Called by JController when a side effect is emitted.
-
notifyIntentCancelled(
JIntent< JState> intent) → void - Called by dispatchers when a cancelled intent finishes.
-
notifyIntentCompleted(
JIntent< JState> intent) → void - Called by dispatchers when an intent finished without failing: reports notifyIntentCancelled if cancellation was requested, otherwise notifyIntentDispatched.
-
notifyIntentDispatched(
JIntent< JState> intent) → void - Called by dispatchers to notify that an intent was dispatched.
-
notifyIntentDropped(
JIntent< JState> intent) → void - Called by dispatchers when an intent is discarded without running.
-
notifyIntentFailed(
JIntent< JState> intent, Object error, StackTrace stackTrace) → void - Called by the intent when its execution fails.
-
notifyIntentStarted(
JIntent< JState> intent) → void - Called by the intent when its execution starts.
-
notifyStateChanged(
JState prev, JState next, [JIntent< JState> ? origin]) → void - Called by JController when the state changes.
-
removeObserver(
JObserverDelegate observer) → bool -
Removes
observer; returns whether it was registered. -
reset(
) → void - Clears every registered observer and static callback.