RtStateObserver
RtStateObserver
is a class that provides a way to observe the lifecycle of states in Reactter.
Syntax
RtStateObserver({ void onBound(RtState state, Object instance)?, void onUnbound(RtState state, Object instance)?, void onCreated(RtState state)?, void onUpdated(RtState state)?, void onDisposed(RtState state)?, });
The RtStateObserver
class accepts these parameters:
-
onBound
: (optional) Called when astate
is bound to aninstance
. -
onUnbound
: (optional) Called when astate
is unbound from aninstance
. -
onCreated
: (optional) Called when astate
is initialized. -
onUpdated
: (optional) Called when astate
undergoes a change or update. -
onDisposed
: (optional) Called when astate
is disposed or cleaned up.
Usage
To use RtStateObserver
, you need to instantiate it, pass the callbacks you want to use and then add it using the Rt.addObserver
method, e.g.:
1import 'package:reactter/reactter.dart';2
3void main() {4 // Create a state observer with lifecycle callbacks5 final stateObserver = RtStateObserver(6 onBound: (state, instance) {7 print('State($state) bound to instance($instance)');8 },9 onUnbound: (state, instance) {10 print('State($state) unbound from instance($instance)');11 },12 onCreated: (state) {13 print('State($state) created');14 },15 onUpdated: (state) {16 print('State($state) updated');17 },18 onDisposed: (state) {19 print('State($state) disposed');20 },21 );22
23 // Add the state observer to Reactter's observer system24 Rt.addObserver(stateObserver);25}