mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 17:11:14 +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> {
|
||||
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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue