refactor: Move event handler registration to the beginning of blocs

pull/440/head
Inex Code 2024-01-31 15:04:59 +04:00
parent f46865ca71
commit fe6f900165
3 changed files with 53 additions and 53 deletions

View File

@ -17,6 +17,37 @@ part 'backups_state.dart';
class BackupsBloc extends Bloc<BackupsEvent, BackupsState> {
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>();
_apiStatusSubscription = connectionRepository.connectionStatusStream
@ -58,37 +89,6 @@ class BackupsBloc extends Bloc<BackupsEvent, BackupsState> {
add(const BackupsServerLoaded());
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();

View File

@ -15,15 +15,6 @@ class ServerJobsBloc extends Bloc<ServerJobsEvent, ServerJobsState> {
: super(
ServerJobsInitialState(),
) {
final apiConnectionRepository = getIt<ApiConnectionRepository>();
_apiDataSubscription = apiConnectionRepository.dataStream.listen(
(final ApiData apiData) {
add(
ServerJobsListChanged([...apiData.serverJobs.data ?? []]),
);
},
);
on<ServerJobsListChanged>(
_mapServerJobsListChangedToState,
);
@ -33,6 +24,15 @@ class ServerJobsBloc extends Bloc<ServerJobsEvent, ServerJobsState> {
on<RemoveAllFinishedJobs>(
_mapRemoveAllFinishedJobsToState,
);
final apiConnectionRepository = getIt<ApiConnectionRepository>();
_apiDataSubscription = apiConnectionRepository.dataStream.listen(
(final ApiData apiData) {
add(
ServerJobsListChanged([...apiData.serverJobs.data ?? []]),
);
},
);
}
StreamSubscription? _apiDataSubscription;

View File

@ -12,6 +12,19 @@ part 'services_state.dart';
class ServicesBloc extends Bloc<ServicesEvent, ServicesState> {
ServicesBloc() : super(ServicesInitial()) {
on<ServicesListUpdate>(
_updateList,
);
on<ServicesReload>(
_reload,
);
on<ServiceRestart>(
_restart,
);
on<ServiceMove>(
_move,
);
final connectionRepository = getIt<ApiConnectionRepository>();
_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(