RtDependencyObserver
Esta página aún no está disponible en tu idioma.
RtDependencyObserver is a class that provides a way to observe the lifecycle of dependencies in Reactter.
Syntax
RtDependencyObserver({ void onRegistered(DependencyRef dependency)?, void onCreated(DependencyRef dependency, Object? instance)?, void onMounted(DependencyRef dependency, Object? instance)?, void onUnmounted(DependencyRef dependency, Object? instance)?, void onDeleted(DependencyRef dependency, Object? instance)?, void onUnregistered(DependencyRef dependency)?, void onFailed(DependencyRef dependency, DependencyFail fail)?, });The RtDependencyObserver class accepts these parameters:
-
onRegistered: (optional) Called when adependencyis registered. -
onCreated: (optional) Called when ainstanceof adependencyis created. -
onMounted: (optional) Called when theinstanceof adependencyis mounted. -
onUnmounted: (optional) Called when theinstanceof adependencyis unmounted. -
onDeleted: (optional) Called when theinstanceof adependencyis deleted. -
onUnregistered: (optional) Called when adependencyis unregistered. -
onFailed: (optional) Called when adependencyfails, indicating one of the following failures:DependencyFail.alreadyRegistered: The dependency is already registered.DependencyFail.alreadyCreated: An instance of dependency is already created.DependencyFail.alreadyDeleted: The instance of dependency is already deleted.DependencyFail.alreadyUnregistered: The dependency is already unregistered.DependencyFail.missingInstanceBuilder: The dependency was not registered previously.DependencyFail.builderRetained: The builder is retained because is in factory mode.DependencyFail.dependencyRetained: The builder and instance is retained because is in singleton mode.DependencyFail.cannotUnregisterActiveInstance: Cannot unregister the dependency because it has an active instance.
Usage
To use RtDependencyObserver , 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 dependency observer with lifecycle callbacks5 final dependencyObserver = RtDependencyObserver(6 onRegistered: (dependency) {7 print('Dependency($dependency) registered');8 },9 onCreated: (dependency, instance) {10 print('Dependency($dependency) created with instance($instance)');11 },12 onMounted: (dependency, instance) {13 print('Dependency($dependency) mounted with instance($instance)');14 },15 onUnmounted: (dependency, instance) {16 print('Dependency($dependency) unmounted with instance($instance)');17 },18 onDeleted: (dependency, instance) {19 print('Dependency($dependency) deleted with instance($instance)');20 },21 onUnregistered: (dependency) {22 print('Dependency($dependency) unregistered');23 },24 onFailed: (dependency, fail) {25 print('Dependency($dependency) failed with $fail');26 },27 );28
29 // Add the dependency observer to Reactter's observer system30 Rt.addObserver(dependencyObserver);31}