mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-24 07:00:47 -04:00
more refactor
This commit is contained in:
parent
ba4ef05a28
commit
b83aa3a64b
39 changed files with 722 additions and 514 deletions
|
@ -262,7 +262,6 @@ class DHTRecord {
|
|||
eventualUpdateBytes(protobufUpdate(fromBuffer, update), subkey: subkey);
|
||||
|
||||
Future<void> watch(
|
||||
Future<void> Function(VeilidUpdateValueChange update) onUpdate,
|
||||
{List<ValueSubkeyRange>? subkeys,
|
||||
Timestamp? expiration,
|
||||
int? count}) async {
|
||||
|
|
|
@ -5,8 +5,8 @@ import 'package:bloc/bloc.dart';
|
|||
|
||||
import '../../veilid_support.dart';
|
||||
|
||||
class DhtRecordCubit<T> extends Cubit<AsyncValue<T>> {
|
||||
DhtRecordCubit({
|
||||
class DHTRecordCubit<T> extends Cubit<AsyncValue<T>> {
|
||||
DHTRecordCubit({
|
||||
required DHTRecord record,
|
||||
required Future<T?> Function(DHTRecord) initialStateFunction,
|
||||
required Future<T?> Function(DHTRecord, List<ValueSubkeyRange>, ValueData)
|
||||
|
@ -48,7 +48,7 @@ class DhtRecordCubit<T> extends Cubit<AsyncValue<T>> {
|
|||
}
|
||||
|
||||
// Cubit that watches the default subkey value of a dhtrecord
|
||||
class DefaultDHTRecordCubit<T> extends DhtRecordCubit<T> {
|
||||
class DefaultDHTRecordCubit<T> extends DHTRecordCubit<T> {
|
||||
DefaultDHTRecordCubit({
|
||||
required super.record,
|
||||
required T Function(List<int> data) decodeState,
|
||||
|
|
|
@ -64,10 +64,12 @@ class TableDBValue<T> extends TableDBBacked<T> {
|
|||
}) : _tableName = tableName,
|
||||
_valueFromJson = valueFromJson,
|
||||
_valueToJson = valueToJson,
|
||||
_tableKeyName = tableKeyName;
|
||||
_tableKeyName = tableKeyName,
|
||||
_streamController = StreamController<T>.broadcast();
|
||||
|
||||
T? get value => _value;
|
||||
T get requireValue => _value!;
|
||||
Stream<T> get stream => _streamController.stream;
|
||||
|
||||
Future<T> get() async {
|
||||
final val = _value;
|
||||
|
@ -80,6 +82,7 @@ class TableDBValue<T> extends TableDBBacked<T> {
|
|||
|
||||
Future<void> set(T newVal) async {
|
||||
_value = await store(newVal);
|
||||
_streamController.add(newVal);
|
||||
}
|
||||
|
||||
T? _value;
|
||||
|
@ -87,6 +90,7 @@ class TableDBValue<T> extends TableDBBacked<T> {
|
|||
final String _tableKeyName;
|
||||
final T Function(Object? obj) _valueFromJson;
|
||||
final Object? Function(T obj) _valueToJson;
|
||||
final StreamController<T> _streamController;
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
/// AsyncTableDBBacked
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue