refactor cubits to keep them alive, wip

This commit is contained in:
Christien Rioux 2024-06-17 23:38:30 -04:00
parent 360ba436f8
commit 3edf2ebb46
13 changed files with 550 additions and 158 deletions

View file

@ -1,12 +1,17 @@
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:bloc_advanced_tools/bloc_advanced_tools.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:veilid_support/veilid_support.dart';
import '../models/models.dart';
import '../repository/account_repository.dart';
class LocalAccountsCubit extends Cubit<IList<LocalAccount>> {
typedef LocalAccountsState = IList<LocalAccount>;
class LocalAccountsCubit extends Cubit<LocalAccountsState>
with StateMapFollowable<LocalAccountsState, TypedKey, LocalAccount> {
LocalAccountsCubit(AccountRepository accountRepository)
: _accountRepository = accountRepository,
super(accountRepository.getLocalAccounts()) {
@ -30,6 +35,14 @@ class LocalAccountsCubit extends Cubit<IList<LocalAccount>> {
await _accountRepositorySubscription.cancel();
}
/// StateMapFollowable /////////////////////////
@override
IMap<TypedKey, LocalAccount> getStateMap(LocalAccountsState state) {
final stateValue = state;
return IMap.fromIterable(stateValue,
keyMapper: (e) => e.superIdentity.recordKey, valueMapper: (e) => e);
}
final AccountRepository _accountRepository;
late final StreamSubscription<AccountRepositoryChange>
_accountRepositorySubscription;