From 4fe8a07d45126b05273e50eb515ae3c7ab46ab88 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Thu, 1 Feb 2024 11:46:09 -0500 Subject: [PATCH] checkpoint --- .../lib/dht_support/src/dht_record_cubit.dart | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/veilid_support/lib/dht_support/src/dht_record_cubit.dart b/packages/veilid_support/lib/dht_support/src/dht_record_cubit.dart index 94bd861..e156ba0 100644 --- a/packages/veilid_support/lib/dht_support/src/dht_record_cubit.dart +++ b/packages/veilid_support/lib/dht_support/src/dht_record_cubit.dart @@ -5,13 +5,17 @@ import 'package:bloc/bloc.dart'; import '../../veilid_support.dart'; +typedef InitialStateFunction = Future Function(DHTRecord); +typedef StateFunction = Future Function( + DHTRecord, List, Uint8List); + class DHTRecordCubit extends Cubit> { DHTRecordCubit({ required Future Function() open, - required Future Function(DHTRecord) initialStateFunction, - required Future Function(DHTRecord, List, Uint8List) - stateFunction, + required InitialStateFunction initialStateFunction, + required StateFunction stateFunction, }) : _wantsCloseRecord = false, + _stateFunction = stateFunction, super(const AsyncValue.loading()) { Future.delayed(Duration.zero, () async { // Do record open/create @@ -27,6 +31,7 @@ class DHTRecordCubit extends Cubit> { required Future Function(DHTRecord, List, Uint8List) stateFunction, }) : _record = record, + _stateFunction = stateFunction, _wantsCloseRecord = false, super(const AsyncValue.loading()) { Future.delayed(Duration.zero, () async { @@ -75,9 +80,12 @@ class DHTRecordCubit extends Cubit> { Future refresh(List subkeys) async { for (final skr in subkeys) { for (var sk = skr.low; sk <= skr.high; sk++) { - final data = await _record.get(subkey: sk, forceRefresh: true); - final newState = await stateFunction(_record, subkeys, data); - xxx continue here + final data = await _record.get( + subkey: sk, forceRefresh: true, onlyUpdates: true); + if (data != null) { + final newState = await _stateFunction(_record, subkeys, data); + xxx remove sk from update + } } } } @@ -85,6 +93,7 @@ class DHTRecordCubit extends Cubit> { StreamSubscription? _subscription; late DHTRecord _record; bool _wantsCloseRecord; + final StateFunction _stateFunction; } // Cubit that watches the default subkey value of a dhtrecord