mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-09 09:31:13 +00:00
refactor: Move event handler registration to the beginning of blocs
This commit is contained in:
parent
f46865ca71
commit
fe6f900165
|
@ -17,6 +17,37 @@ part 'backups_state.dart';
|
||||||
|
|
||||||
class BackupsBloc extends Bloc<BackupsEvent, BackupsState> {
|
class BackupsBloc extends Bloc<BackupsEvent, BackupsState> {
|
||||||
BackupsBloc() : super(BackupsInitial()) {
|
BackupsBloc() : super(BackupsInitial()) {
|
||||||
|
on<BackupsServerLoaded>(
|
||||||
|
_loadState,
|
||||||
|
);
|
||||||
|
on<BackupsServerReset>(
|
||||||
|
_resetState,
|
||||||
|
);
|
||||||
|
on<BackupsStateChanged>(
|
||||||
|
_updateState,
|
||||||
|
);
|
||||||
|
on<InitializeBackupsRepository>(
|
||||||
|
_initializeRepository,
|
||||||
|
);
|
||||||
|
on<ForceSnapshotListUpdate>(
|
||||||
|
_forceSnapshotListUpdate,
|
||||||
|
);
|
||||||
|
on<CreateBackups>(
|
||||||
|
_createBackups,
|
||||||
|
);
|
||||||
|
on<RestoreBackup>(
|
||||||
|
_restoreBackup,
|
||||||
|
);
|
||||||
|
on<SetAutobackupPeriod>(
|
||||||
|
_setAutobackupPeriod,
|
||||||
|
);
|
||||||
|
on<SetAutobackupQuotas>(
|
||||||
|
_setAutobackupQuotas,
|
||||||
|
);
|
||||||
|
on<ForgetSnapshot>(
|
||||||
|
_forgetSnapshot,
|
||||||
|
);
|
||||||
|
|
||||||
final connectionRepository = getIt<ApiConnectionRepository>();
|
final connectionRepository = getIt<ApiConnectionRepository>();
|
||||||
|
|
||||||
_apiStatusSubscription = connectionRepository.connectionStatusStream
|
_apiStatusSubscription = connectionRepository.connectionStatusStream
|
||||||
|
@ -58,37 +89,6 @@ class BackupsBloc extends Bloc<BackupsEvent, BackupsState> {
|
||||||
add(const BackupsServerLoaded());
|
add(const BackupsServerLoaded());
|
||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
on<BackupsServerLoaded>(
|
|
||||||
_loadState,
|
|
||||||
);
|
|
||||||
on<BackupsServerReset>(
|
|
||||||
_resetState,
|
|
||||||
);
|
|
||||||
on<BackupsStateChanged>(
|
|
||||||
_updateState,
|
|
||||||
);
|
|
||||||
on<InitializeBackupsRepository>(
|
|
||||||
_initializeRepository,
|
|
||||||
);
|
|
||||||
on<ForceSnapshotListUpdate>(
|
|
||||||
_forceSnapshotListUpdate,
|
|
||||||
);
|
|
||||||
on<CreateBackups>(
|
|
||||||
_createBackups,
|
|
||||||
);
|
|
||||||
on<RestoreBackup>(
|
|
||||||
_restoreBackup,
|
|
||||||
);
|
|
||||||
on<SetAutobackupPeriod>(
|
|
||||||
_setAutobackupPeriod,
|
|
||||||
);
|
|
||||||
on<SetAutobackupQuotas>(
|
|
||||||
_setAutobackupQuotas,
|
|
||||||
);
|
|
||||||
on<ForgetSnapshot>(
|
|
||||||
_forgetSnapshot,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final BackblazeApi backblaze = BackblazeApi();
|
final BackblazeApi backblaze = BackblazeApi();
|
||||||
|
|
|
@ -15,15 +15,6 @@ class ServerJobsBloc extends Bloc<ServerJobsEvent, ServerJobsState> {
|
||||||
: super(
|
: super(
|
||||||
ServerJobsInitialState(),
|
ServerJobsInitialState(),
|
||||||
) {
|
) {
|
||||||
final apiConnectionRepository = getIt<ApiConnectionRepository>();
|
|
||||||
_apiDataSubscription = apiConnectionRepository.dataStream.listen(
|
|
||||||
(final ApiData apiData) {
|
|
||||||
add(
|
|
||||||
ServerJobsListChanged([...apiData.serverJobs.data ?? []]),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
on<ServerJobsListChanged>(
|
on<ServerJobsListChanged>(
|
||||||
_mapServerJobsListChangedToState,
|
_mapServerJobsListChangedToState,
|
||||||
);
|
);
|
||||||
|
@ -33,6 +24,15 @@ class ServerJobsBloc extends Bloc<ServerJobsEvent, ServerJobsState> {
|
||||||
on<RemoveAllFinishedJobs>(
|
on<RemoveAllFinishedJobs>(
|
||||||
_mapRemoveAllFinishedJobsToState,
|
_mapRemoveAllFinishedJobsToState,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final apiConnectionRepository = getIt<ApiConnectionRepository>();
|
||||||
|
_apiDataSubscription = apiConnectionRepository.dataStream.listen(
|
||||||
|
(final ApiData apiData) {
|
||||||
|
add(
|
||||||
|
ServerJobsListChanged([...apiData.serverJobs.data ?? []]),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamSubscription? _apiDataSubscription;
|
StreamSubscription? _apiDataSubscription;
|
||||||
|
|
|
@ -12,6 +12,19 @@ part 'services_state.dart';
|
||||||
|
|
||||||
class ServicesBloc extends Bloc<ServicesEvent, ServicesState> {
|
class ServicesBloc extends Bloc<ServicesEvent, ServicesState> {
|
||||||
ServicesBloc() : super(ServicesInitial()) {
|
ServicesBloc() : super(ServicesInitial()) {
|
||||||
|
on<ServicesListUpdate>(
|
||||||
|
_updateList,
|
||||||
|
);
|
||||||
|
on<ServicesReload>(
|
||||||
|
_reload,
|
||||||
|
);
|
||||||
|
on<ServiceRestart>(
|
||||||
|
_restart,
|
||||||
|
);
|
||||||
|
on<ServiceMove>(
|
||||||
|
_move,
|
||||||
|
);
|
||||||
|
|
||||||
final connectionRepository = getIt<ApiConnectionRepository>();
|
final connectionRepository = getIt<ApiConnectionRepository>();
|
||||||
|
|
||||||
_apiDataSubscription = connectionRepository.dataStream.listen(
|
_apiDataSubscription = connectionRepository.dataStream.listen(
|
||||||
|
@ -29,19 +42,6 @@ class ServicesBloc extends Bloc<ServicesEvent, ServicesState> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
on<ServicesListUpdate>(
|
|
||||||
_updateList,
|
|
||||||
);
|
|
||||||
on<ServicesReload>(
|
|
||||||
_reload,
|
|
||||||
);
|
|
||||||
on<ServiceRestart>(
|
|
||||||
_restart,
|
|
||||||
);
|
|
||||||
on<ServiceMove>(
|
|
||||||
_move,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateList(
|
Future<void> _updateList(
|
||||||
|
|
Loading…
Reference in a new issue