Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providers_tracker #47

Merged
merged 2 commits into from
Dec 18, 2024
Merged

Providers_tracker #47

merged 2 commits into from
Dec 18, 2024

Conversation

Chralu
Copy link
Collaborator

@Chralu Chralu commented Dec 18, 2024

ProvidersTracker keeps track of alive providers.

Usage in production is not recommended.

Howto use

Register the observer

import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' as aedappfm;
runApp(
 ProviderScope(
   observers: [
     if (kDebugMode) aedappfm.ProvidersTracker(),
   ],
   child: const MyApp(),
 ),
;

Check all alive providers

In debug console, check ProvidersTracker content :

Command :

aedappfm.ProvidersTracker().aliveProviders

Result :

Set
[0] = AutoDisposeProvider (oracleServiceProvider:AutoDisposeProvider<OracleService>#2d1c8)
[1] = AutoDisposeAsyncNotifierProviderImpl (_archethicOracleUCONotifierProvider:AutoDisposeAsyncNotifierProviderImpl<_ArchethicOracleUCONotifier, ArchethicOracleUCO>#4aa30)
[2] = AutoDisposeProvider (apiServiceProvider:AutoDisposeProvider<ApiService>#e4552)

Filter and READ providers

In debug console :

Command :

aedappfm.ProvidersTracker().byName('oracle').read

Result :

Set
[0] = AutoDisposeProvider (oracleServiceProvider:AutoDisposeProvider<OracleService>#2d1c8)
[1] = AutoDisposeAsyncNotifierProviderImpl (_archethicOracleUCONotifierProvider:AutoDisposeAsyncNotifierProviderImpl<_ArchethicOracleUCONotifier, ArchethicOracleUCO>#4aa30)

Filter and WATCH providers

In debug console :

Command :

// watch returns a stream. Here we just log the number of providers whose name matches 'oracle'
aedappfm.ProvidersTracker().byName('oracle').watch.forEach((providers) => print('>>> Oracle : ${providers.length}'))

Result :

Each time the alive providers matching 'oracle' changes, we have a log like this :

>>> Oracle : 2

@Chralu Chralu requested a review from redDwarf03 December 18, 2024 16:09
@Chralu Chralu merged commit c8c8a2c into main Dec 18, 2024
2 checks passed
@Chralu Chralu deleted the providers_tracker branch December 18, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant