From 99cadf98d205a9d36090d86de84f85f4e1fb95e4 Mon Sep 17 00:00:00 2001 From: appflowy Date: Mon, 31 Jan 2022 08:47:06 +0800 Subject: [PATCH] remove app interface --- .../workspace/application/app/app_bloc.dart | 24 ++++---- .../app_flowy/lib/workspace/domain/i_app.dart | 22 -------- .../infrastructure/deps_resolver.dart | 10 +--- .../workspace/infrastructure/i_app_impl.dart | 55 ------------------- .../infrastructure/repos/app_repo.dart | 24 +++++--- 5 files changed, 29 insertions(+), 106 deletions(-) delete mode 100644 frontend/app_flowy/lib/workspace/domain/i_app.dart delete mode 100644 frontend/app_flowy/lib/workspace/infrastructure/i_app_impl.dart diff --git a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart index 438941fe2f..4be21331b7 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart @@ -1,4 +1,4 @@ -import 'package:app_flowy/workspace/domain/i_app.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; @@ -10,18 +10,18 @@ import 'package:dartz/dartz.dart'; part 'app_bloc.freezed.dart'; class AppBloc extends Bloc { - final IApp appManager; - final IAppListenr listener; - AppBloc({required App app, required this.appManager, required this.listener}) : super(AppState.initial(app)) { + final AppRepository repo; + final AppListenerRepository listener; + AppBloc({required App app, required this.repo, required this.listener}) : super(AppState.initial(app)) { on((event, emit) async { await event.map(initial: (e) async { - listener.start( - viewsChangeCallback: _handleViewsChanged, - updatedCallback: (app) => add(AppEvent.appDidUpdate(app)), + listener.startListening( + viewsChanged: _handleViewsChanged, + appUpdated: (app) => add(AppEvent.appDidUpdate(app)), ); await _fetchViews(emit); }, createView: (CreateView value) async { - final viewOrFailed = await appManager.createView(name: value.name, desc: value.desc, viewType: value.viewType); + final viewOrFailed = await repo.createView(name: value.name, desc: value.desc, viewType: value.viewType); viewOrFailed.fold( (view) => emit(state.copyWith( latestCreatedView: view, @@ -35,13 +35,13 @@ class AppBloc extends Bloc { }, didReceiveViews: (e) async { await handleDidReceiveViews(e.views, emit); }, delete: (e) async { - final result = await appManager.delete(); + final result = await repo.delete(); result.fold( (unit) => emit(state.copyWith(successOrFailure: left(unit))), (error) => emit(state.copyWith(successOrFailure: right(error))), ); }, rename: (e) async { - final result = await appManager.rename(e.newName); + final result = await repo.updateApp(name: e.newName); result.fold( (l) => emit(state.copyWith(successOrFailure: left(unit))), (error) => emit(state.copyWith(successOrFailure: right(error))), @@ -54,7 +54,7 @@ class AppBloc extends Bloc { @override Future close() async { - await listener.stop(); + await listener.close(); return super.close(); } @@ -81,7 +81,7 @@ class AppBloc extends Bloc { } Future _fetchViews(Emitter emit) async { - final viewsOrFailed = await appManager.getViews(); + final viewsOrFailed = await repo.getViews(); viewsOrFailed.fold( (apps) => emit(state.copyWith(views: apps)), (error) { diff --git a/frontend/app_flowy/lib/workspace/domain/i_app.dart b/frontend/app_flowy/lib/workspace/domain/i_app.dart deleted file mode 100644 index a276c71a0a..0000000000 --- a/frontend/app_flowy/lib/workspace/domain/i_app.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; - -typedef AppUpdatedCallback = void Function(App app); -typedef AppViewsChangeCallback = void Function(Either, FlowyError> viewsOrFailed); - -abstract class IApp { - Future, FlowyError>> getViews(); - - Future> createView({required String name, String? desc, required ViewType viewType}); - - Future> delete(); - - Future> rename(String newName); -} - -abstract class IAppListenr { - void start({AppViewsChangeCallback? viewsChangeCallback, AppUpdatedCallback? updatedCallback}); - - Future stop(); -} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 5b481f9421..7c067a3d14 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -11,7 +11,6 @@ import 'package:app_flowy/workspace/domain/i_share.dart'; import 'package:app_flowy/workspace/domain/i_trash.dart'; import 'package:app_flowy/workspace/domain/i_view.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; -import 'package:app_flowy/workspace/infrastructure/i_app_impl.dart'; import 'package:app_flowy/workspace/infrastructure/i_doc_impl.dart'; import 'package:app_flowy/workspace/infrastructure/i_trash_impl.dart'; import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; @@ -39,11 +38,6 @@ class HomeDepsResolver { ), ); - //App - getIt.registerFactoryParam((appId, _) => IAppImpl(repo: AppRepository(appId: appId))); - getIt.registerFactoryParam( - (appId, _) => IAppListenerhImpl(repo: AppListenerRepository(appId: appId))); - //workspace getIt.registerFactoryParam( (user, workspaceId) => WorkspaceListener(repo: WorkspaceListenerRepo(user: user, workspaceId: workspaceId))); @@ -81,8 +75,8 @@ class HomeDepsResolver { getIt.registerFactoryParam( (app, _) => AppBloc( app: app, - appManager: getIt(param1: app.id), - listener: getIt(param1: app.id), + repo: AppRepository(appId: app.id), + listener: AppListenerRepository(appId: app.id), ), ); diff --git a/frontend/app_flowy/lib/workspace/infrastructure/i_app_impl.dart b/frontend/app_flowy/lib/workspace/infrastructure/i_app_impl.dart deleted file mode 100644 index cfb92287df..0000000000 --- a/frontend/app_flowy/lib/workspace/infrastructure/i_app_impl.dart +++ /dev/null @@ -1,55 +0,0 @@ -import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; -import 'package:dartz/dartz.dart'; -import 'package:app_flowy/workspace/domain/i_app.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -export 'package:app_flowy/workspace/domain/i_app.dart'; - -class IAppImpl extends IApp { - AppRepository repo; - IAppImpl({ - required this.repo, - }); - - @override - Future, FlowyError>> getViews() { - return repo.getViews(); - } - - @override - Future> createView({required String name, String? desc, required ViewType viewType}) { - return repo.createView(name, desc ?? "", viewType).then((result) { - return result.fold( - (view) => left(view), - (r) => right(r), - ); - }); - } - - @override - Future> delete() { - return repo.delete(); - } - - @override - Future> rename(String newName) { - return repo.updateApp(name: newName); - } -} - -class IAppListenerhImpl extends IAppListenr { - AppListenerRepository repo; - IAppListenerhImpl({ - required this.repo, - }); - - @override - Future stop() async { - await repo.close(); - } - - @override - void start({AppViewsChangeCallback? viewsChangeCallback, AppUpdatedCallback? updatedCallback}) { - repo.startListening(viewsChanged: viewsChangeCallback, update: updatedCallback); - } -} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart b/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart index e3dc00cf6b..0077f718eb 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/workspace/domain/i_app.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; @@ -24,7 +23,11 @@ class AppRepository { return FolderEventReadApp(request).send(); } - Future> createView(String name, String desc, ViewType viewType) { + Future> createView({ + required String name, + required String desc, + required ViewType viewType, + }) { final request = CreateViewRequest.create() ..belongToId = appId ..name = name @@ -60,10 +63,13 @@ class AppRepository { } } +typedef AppDidUpdateCallback = void Function(App app); +typedef ViewsDidChangeCallback = void Function(Either, FlowyError> viewsOrFailed); + class AppListenerRepository { StreamSubscription? _subscription; - AppViewsChangeCallback? _viewsChanged; - AppUpdatedCallback? _update; + ViewsDidChangeCallback? _viewsChanged; + AppDidUpdateCallback? _updated; late FolderNotificationParser _parser; String appId; @@ -71,9 +77,9 @@ class AppListenerRepository { required this.appId, }); - void startListening({AppViewsChangeCallback? viewsChanged, AppUpdatedCallback? update}) { + void startListening({ViewsDidChangeCallback? viewsChanged, AppDidUpdateCallback? appUpdated}) { _viewsChanged = viewsChanged; - _update = update; + _updated = appUpdated; _parser = FolderNotificationParser(id: appId, callback: _bservableCallback); _subscription = RustStreamReceiver.listen((observable) => _parser.parse(observable)); } @@ -92,11 +98,11 @@ class AppListenerRepository { } break; case FolderNotification.AppUpdated: - if (_update != null) { + if (_updated != null) { result.fold( (payload) { final app = App.fromBuffer(payload); - _update!(app); + _updated!(app); }, (error) => Log.error(error), ); @@ -110,6 +116,6 @@ class AppListenerRepository { Future close() async { await _subscription?.cancel(); _viewsChanged = null; - _update = null; + _updated = null; } }