From a529a3bf43807d4587d5f505036b9bae0b410276 Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 21 Jul 2021 17:05:51 +0800 Subject: [PATCH] config workspace and app repo callback --- .../lib/home/application/menu/menu_bloc.dart | 8 +- app_flowy/lib/home/domain/i_app.dart | 6 - app_flowy/lib/home/domain/i_workspace.dart | 10 ++ .../lib/home/infrastructure/app_repo.dart | 65 ----------- .../home/infrastructure/deps_resolver.dart | 14 ++- .../lib/home/infrastructure/i_app_impl.dart | 15 +-- .../home/infrastructure/i_workspace_impl.dart | 26 +++++ .../home/infrastructure/repos/app_repo.dart | 107 ++++++++++++++++++ .../infrastructure/repos/workspace_repo.dart | 89 +++++++++++++++ .../flowy-workspace/observable.pbenum.dart | 24 ++-- .../flowy-workspace/observable.pbjson.dart | 16 +-- .../src/derive_cache/derive_cache.rs | 2 +- rust-lib/flowy-observable/Flowy.toml | 2 +- .../src/observable/observable.rs | 23 ++-- .../src/protobuf/model/observable.rs | 67 ++++++----- .../src/protobuf/proto/observable.proto | 8 +- .../src/services/app_controller.rs | 4 +- 17 files changed, 331 insertions(+), 155 deletions(-) create mode 100644 app_flowy/lib/home/domain/i_workspace.dart delete mode 100644 app_flowy/lib/home/infrastructure/app_repo.dart create mode 100644 app_flowy/lib/home/infrastructure/i_workspace_impl.dart create mode 100644 app_flowy/lib/home/infrastructure/repos/app_repo.dart create mode 100644 app_flowy/lib/home/infrastructure/repos/workspace_repo.dart diff --git a/app_flowy/lib/home/application/menu/menu_bloc.dart b/app_flowy/lib/home/application/menu/menu_bloc.dart index 5bd8951d15..f286da50c3 100644 --- a/app_flowy/lib/home/application/menu/menu_bloc.dart +++ b/app_flowy/lib/home/application/menu/menu_bloc.dart @@ -1,5 +1,5 @@ import 'dart:async'; -import 'package:app_flowy/home/domain/i_app.dart'; +import 'package:app_flowy/home/domain/i_workspace.dart'; import 'package:app_flowy/home/domain/page_context.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; @@ -11,8 +11,8 @@ part 'menu_state.dart'; part 'menu_bloc.freezed.dart'; class MenuBloc extends Bloc { - final IApp iAppImpl; - MenuBloc(this.iAppImpl) : super(MenuState.initial()); + final IWorkspace iWorkspaceImpl; + MenuBloc(this.iWorkspaceImpl) : super(MenuState.initial()); @override Stream mapEventToState( @@ -37,7 +37,7 @@ class MenuBloc extends Bloc { } Stream _performActionOnCreateApp(_CreateApp event) async* { - await iAppImpl + await iWorkspaceImpl .createApp(name: event.name, desc: event.desc) .then((result) async* { result.fold( diff --git a/app_flowy/lib/home/domain/i_app.dart b/app_flowy/lib/home/domain/i_app.dart index 04d99cdf8f..5d022ae697 100644 --- a/app_flowy/lib/home/domain/i_app.dart +++ b/app_flowy/lib/home/domain/i_app.dart @@ -2,12 +2,6 @@ import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart'; import 'package:dartz/dartz.dart'; abstract class IApp { - Future> createApp( - {required String name, String? desc}); - - Future, WorkspaceError>> getApps( - {required String workspaceId}); - Future, WorkspaceError>> getViews({required String appId}); Future> createView( diff --git a/app_flowy/lib/home/domain/i_workspace.dart b/app_flowy/lib/home/domain/i_workspace.dart new file mode 100644 index 0000000000..8201ee2ea9 --- /dev/null +++ b/app_flowy/lib/home/domain/i_workspace.dart @@ -0,0 +1,10 @@ +import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart'; +import 'package:dartz/dartz.dart'; + +abstract class IWorkspace { + Future> createApp( + {required String name, String? desc}); + + Future, WorkspaceError>> getApps( + {required String workspaceId}); +} diff --git a/app_flowy/lib/home/infrastructure/app_repo.dart b/app_flowy/lib/home/infrastructure/app_repo.dart deleted file mode 100644 index c42f66db16..0000000000 --- a/app_flowy/lib/home/infrastructure/app_repo.dart +++ /dev/null @@ -1,65 +0,0 @@ -import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/dispatch/dispatch.dart'; -import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-workspace/app_query.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pbenum.dart'; -import 'package:flowy_sdk/protobuf/flowy-workspace/workspace_query.pb.dart'; - -class AppRepository { - Future> createApp(String appName, String desc) { - return WorkspaceEventGetCurWorkspace().send().then((result) { - return result.fold( - (workspace) { - final request = CreateAppRequest.create() - ..name = appName - ..workspaceId = workspace.id - ..desc = desc; - return WorkspaceEventCreateApp(request).send(); - }, - (error) { - return right(error); - }, - ); - }); - } - - Future, WorkspaceError>> getApps( - {required String workspaceId}) { - final request = QueryWorkspaceRequest.create() - ..workspaceId = workspaceId - ..readApps = true; - - return WorkspaceEventGetWorkspace(request).send().then((result) { - return result.fold( - (workspace) => left(workspace.apps.items), - (error) => right(error), - ); - }); - } - - Future, WorkspaceError>> getViews({required String appId}) { - final request = QueryAppRequest.create() - ..appId = appId - ..readViews = true; - - return WorkspaceEventGetApp(request).send().then((result) { - return result.fold( - (app) => left(app.views.items), - (error) => right(error), - ); - }); - } - - Future> createView( - String appId, String name, String desc, ViewTypeIdentifier viewType) { - final request = CreateViewRequest.create() - ..appId = appId - ..name = name - ..desc = desc - ..viewType = viewType; - - return WorkspaceEventCreateView(request).send(); - } -} diff --git a/app_flowy/lib/home/infrastructure/deps_resolver.dart b/app_flowy/lib/home/infrastructure/deps_resolver.dart index 5ca9d072c7..cc7d6e6413 100644 --- a/app_flowy/lib/home/infrastructure/deps_resolver.dart +++ b/app_flowy/lib/home/infrastructure/deps_resolver.dart @@ -1,16 +1,24 @@ import 'package:app_flowy/home/application/menu/menu_bloc.dart'; -import 'package:app_flowy/home/infrastructure/app_repo.dart'; import 'package:app_flowy/home/infrastructure/i_app_impl.dart'; +import 'package:app_flowy/home/infrastructure/i_workspace_impl.dart'; +import 'package:app_flowy/home/infrastructure/repos/app_repo.dart'; +import 'package:app_flowy/home/infrastructure/repos/workspace_repo.dart'; import 'package:get_it/get_it.dart'; class HomeDepsResolver { static Future resolve(GetIt getIt) async { - getIt.registerLazySingleton(() => AppRepository()); + getIt.registerLazySingleton( + () => WorkspaceRepository()); + + getIt.registerFactoryParam( + (appId, _) => AppRepository(appId: appId)); //Interface implementation getIt.registerFactory(() => IAppImpl(repo: getIt())); + getIt.registerFactory( + () => IWorkspaceImpl(repo: getIt())); //Bloc - getIt.registerFactory(() => MenuBloc(getIt())); + getIt.registerFactory(() => MenuBloc(getIt())); } } diff --git a/app_flowy/lib/home/infrastructure/i_app_impl.dart b/app_flowy/lib/home/infrastructure/i_app_impl.dart index 6206bf7938..a5ccfbd33c 100644 --- a/app_flowy/lib/home/infrastructure/i_app_impl.dart +++ b/app_flowy/lib/home/infrastructure/i_app_impl.dart @@ -1,8 +1,7 @@ +import 'package:app_flowy/home/infrastructure/repos/app_repo.dart'; import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; import 'package:app_flowy/home/domain/i_app.dart'; -import 'package:app_flowy/home/infrastructure/app_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; export 'package:app_flowy/home/domain/i_app.dart'; @@ -13,18 +12,6 @@ class IAppImpl extends IApp { required this.repo, }); - @override - Future> createApp( - {required String name, String? desc}) { - return repo.createApp(name, desc ?? ""); - } - - @override - Future, WorkspaceError>> getApps( - {required String workspaceId}) { - return repo.getApps(workspaceId: workspaceId); - } - @override Future, WorkspaceError>> getViews({required String appId}) { return repo.getViews(appId: appId); diff --git a/app_flowy/lib/home/infrastructure/i_workspace_impl.dart b/app_flowy/lib/home/infrastructure/i_workspace_impl.dart new file mode 100644 index 0000000000..70a0248629 --- /dev/null +++ b/app_flowy/lib/home/infrastructure/i_workspace_impl.dart @@ -0,0 +1,26 @@ +import 'package:app_flowy/home/domain/i_workspace.dart'; +import 'package:app_flowy/home/infrastructure/repos/workspace_repo.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; + +export 'package:app_flowy/home/domain/i_workspace.dart'; + +class IWorkspaceImpl extends IWorkspace { + WorkspaceRepository repo; + IWorkspaceImpl({ + required this.repo, + }); + + @override + Future> createApp( + {required String name, String? desc}) { + return repo.createApp(name, desc ?? ""); + } + + @override + Future, WorkspaceError>> getApps( + {required String workspaceId}) { + return repo.getApps(workspaceId: workspaceId); + } +} diff --git a/app_flowy/lib/home/infrastructure/repos/app_repo.dart b/app_flowy/lib/home/infrastructure/repos/app_repo.dart new file mode 100644 index 0000000000..4e444b9c36 --- /dev/null +++ b/app_flowy/lib/home/infrastructure/repos/app_repo.dart @@ -0,0 +1,107 @@ +import 'dart:async'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_infra/flowy_logger.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-observable/subject.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_query.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/observable.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pbenum.dart'; +import 'package:flowy_sdk/rust_stream.dart'; + +typedef AppUpdatedCallback = void Function(String name, String desc); +typedef ViewUpdatedCallback = void Function(List views); + +class AppRepository { + StreamSubscription? _subscription; + ViewUpdatedCallback? _viewUpdatedCallback; + AppUpdatedCallback? _appUpdatedCallback; + String appId; + AppRepository({ + required this.appId, + }); + + Future> getAppDesc() { + final request = QueryAppRequest.create() + ..appId = appId + ..readViews = false; + + return WorkspaceEventGetApp(request).send(); + } + + Future> createView( + String appId, String name, String desc, ViewTypeIdentifier viewType) { + final request = CreateViewRequest.create() + ..appId = appId + ..name = name + ..desc = desc + ..viewType = viewType; + + return WorkspaceEventCreateView(request).send(); + } + + Future, WorkspaceError>> getViews({required String appId}) { + final request = QueryAppRequest.create() + ..appId = appId + ..readViews = true; + + return WorkspaceEventGetApp(request).send().then((result) { + return result.fold( + (app) => left(app.views.items), + (error) => right(error), + ); + }); + } + + void startWatching( + {ViewUpdatedCallback? viewUpdatedCallback, + AppUpdatedCallback? appUpdatedCallback}) { + _viewUpdatedCallback = viewUpdatedCallback; + _appUpdatedCallback = appUpdatedCallback; + _subscription = RustStreamReceiver.listen((observable) { + if (observable.subjectId != appId) { + return; + } + + final ty = WorkspaceObservableType.valueOf(observable.ty); + if (ty != null) { + _handleObservableType(ty); + } + }); + } + + void _handleObservableType(WorkspaceObservableType ty) { + switch (ty) { + case WorkspaceObservableType.ViewUpdated: + if (_viewUpdatedCallback == null) { + return; + } + getViews(appId: appId).then((result) { + result.fold( + (views) => _viewUpdatedCallback!(views), + (error) => Log.error(error), + ); + }); + break; + case WorkspaceObservableType.AppDescUpdated: + if (_appUpdatedCallback == null) { + return; + } + getAppDesc().then((result) { + result.fold( + (app) => _appUpdatedCallback!(app.name, app.desc), + (error) => Log.error(error), + ); + }); + break; + default: + break; + } + } + + Future close() async { + await _subscription?.cancel(); + } +} diff --git a/app_flowy/lib/home/infrastructure/repos/workspace_repo.dart b/app_flowy/lib/home/infrastructure/repos/workspace_repo.dart new file mode 100644 index 0000000000..9ab2555900 --- /dev/null +++ b/app_flowy/lib/home/infrastructure/repos/workspace_repo.dart @@ -0,0 +1,89 @@ +import 'dart:async'; + +import 'package:dartz/dartz.dart'; +import 'package:flowy_infra/flowy_logger.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-observable/subject.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/observable.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/workspace_query.pb.dart'; +import 'package:flowy_sdk/rust_stream.dart'; + +typedef AppUpdatedCallback = void Function(List apps); + +class WorkspaceRepository { + StreamSubscription? _subscription; + AppUpdatedCallback? _appUpdatedCallback; + String workspaceId; + WorkspaceRepository({ + required this.workspaceId, + }); + + Future> createApp(String appName, String desc) { + return WorkspaceEventGetCurWorkspace().send().then((result) { + return result.fold( + (workspace) { + final request = CreateAppRequest.create() + ..name = appName + ..workspaceId = workspace.id + ..desc = desc; + return WorkspaceEventCreateApp(request).send(); + }, + (error) { + return right(error); + }, + ); + }); + } + + Future, WorkspaceError>> getApps( + {required String workspaceId}) { + final request = QueryWorkspaceRequest.create() + ..workspaceId = workspaceId + ..readApps = true; + + return WorkspaceEventGetWorkspace(request).send().then((result) { + return result.fold( + (workspace) => left(workspace.apps.items), + (error) => right(error), + ); + }); + } + + void startWatching({AppUpdatedCallback? appUpdatedCallback}) { + _appUpdatedCallback = appUpdatedCallback; + _subscription = RustStreamReceiver.listen((observable) { + if (observable.subjectId != workspaceId) { + return; + } + + final ty = WorkspaceObservableType.valueOf(observable.ty); + if (ty != null) { + _handleObservableType(ty); + } + }); + } + + void _handleObservableType(WorkspaceObservableType ty) { + switch (ty) { + case WorkspaceObservableType.WorkspaceUpdated: + if (_appUpdatedCallback == null) { + return; + } + getApps(workspaceId: workspaceId).then((result) { + result.fold( + (apps) => _appUpdatedCallback!(apps), + (error) => Log.error(error), + ); + }); + break; + default: + break; + } + } + + Future close() async { + await _subscription?.cancel(); + } +} diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart index 38e98519cd..31c9b65b5c 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart @@ -9,20 +9,24 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; -class ObservableType extends $pb.ProtobufEnum { - static const ObservableType Unknown = ObservableType._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); - static const ObservableType WorkspaceDidUpdate = ObservableType._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceDidUpdate'); - static const ObservableType AppDidUpdate = ObservableType._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppDidUpdate'); +class WorkspaceObservableType extends $pb.ProtobufEnum { + static const WorkspaceObservableType Unknown = WorkspaceObservableType._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); + static const WorkspaceObservableType WorkspaceUpdated = WorkspaceObservableType._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceUpdated'); + static const WorkspaceObservableType AppDescUpdated = WorkspaceObservableType._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppDescUpdated'); + static const WorkspaceObservableType AppViewsUpdated = WorkspaceObservableType._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppViewsUpdated'); + static const WorkspaceObservableType ViewUpdated = WorkspaceObservableType._(30, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewUpdated'); - static const $core.List values = [ + static const $core.List values = [ Unknown, - WorkspaceDidUpdate, - AppDidUpdate, + WorkspaceUpdated, + AppDescUpdated, + AppViewsUpdated, + ViewUpdated, ]; - static final $core.Map<$core.int, ObservableType> _byValue = $pb.ProtobufEnum.initByValue(values); - static ObservableType? valueOf($core.int value) => _byValue[value]; + static final $core.Map<$core.int, WorkspaceObservableType> _byValue = $pb.ProtobufEnum.initByValue(values); + static WorkspaceObservableType? valueOf($core.int value) => _byValue[value]; - const ObservableType._($core.int v, $core.String n) : super(v, n); + const WorkspaceObservableType._($core.int v, $core.String n) : super(v, n); } diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart index 0b2b0d47f6..1f960b9ea7 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart @@ -8,15 +8,17 @@ import 'dart:core' as $core; import 'dart:convert' as $convert; import 'dart:typed_data' as $typed_data; -@$core.Deprecated('Use observableTypeDescriptor instead') -const ObservableType$json = const { - '1': 'ObservableType', +@$core.Deprecated('Use workspaceObservableTypeDescriptor instead') +const WorkspaceObservableType$json = const { + '1': 'WorkspaceObservableType', '2': const [ const {'1': 'Unknown', '2': 0}, - const {'1': 'WorkspaceDidUpdate', '2': 10}, - const {'1': 'AppDidUpdate', '2': 11}, + const {'1': 'WorkspaceUpdated', '2': 10}, + const {'1': 'AppDescUpdated', '2': 20}, + const {'1': 'AppViewsUpdated', '2': 21}, + const {'1': 'ViewUpdated', '2': 30}, ], }; -/// Descriptor for `ObservableType`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List observableTypeDescriptor = $convert.base64Decode('Cg5PYnNlcnZhYmxlVHlwZRILCgdVbmtub3duEAASFgoSV29ya3NwYWNlRGlkVXBkYXRlEAoSEAoMQXBwRGlkVXBkYXRlEAs='); +/// Descriptor for `WorkspaceObservableType`. Decode as a `google.protobuf.EnumDescriptorProto`. +final $typed_data.Uint8List workspaceObservableTypeDescriptor = $convert.base64Decode('ChdXb3Jrc3BhY2VPYnNlcnZhYmxlVHlwZRILCgdVbmtub3duEAASFAoQV29ya3NwYWNlVXBkYXRlZBAKEhIKDkFwcERlc2NVcGRhdGVkEBQSEwoPQXBwVmlld3NVcGRhdGVkEBUSDwoLVmlld1VwZGF0ZWQQHg=='); diff --git a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs index 1448fc51c5..d1e9a6f19c 100644 --- a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs +++ b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs @@ -46,7 +46,7 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { "ViewTypeIdentifier" | "WorkspaceEvent" | "WorkspaceErrorCode" - | "ObservableType" + | "WorkspaceObservableType" | "FFIStatusCode" | "UserStatus" | "UserEvent" diff --git a/rust-lib/flowy-observable/Flowy.toml b/rust-lib/flowy-observable/Flowy.toml index 93f30162a8..33b1c193f2 100644 --- a/rust-lib/flowy-observable/Flowy.toml +++ b/rust-lib/flowy-observable/Flowy.toml @@ -1,3 +1,3 @@ proto_crates = ["src/entities"] -event_files = [""] \ No newline at end of file +event_files = [] \ No newline at end of file diff --git a/rust-lib/flowy-workspace/src/observable/observable.rs b/rust-lib/flowy-workspace/src/observable/observable.rs index 91b299da1e..bb5d45d968 100644 --- a/rust-lib/flowy-workspace/src/observable/observable.rs +++ b/rust-lib/flowy-workspace/src/observable/observable.rs @@ -4,25 +4,26 @@ use flowy_observable::{dart::RustStreamSender, entities::ObservableSubject}; const OBSERVABLE_CATEGORY: &'static str = "Workspace"; #[derive(ProtoBuf_Enum, Debug)] -pub(crate) enum ObservableType { - Unknown = 0, - - WorkspaceDidUpdate = 10, - AppDidUpdate = 11, +pub(crate) enum WorkspaceObservableType { + Unknown = 0, + WorkspaceUpdated = 10, + AppDescUpdated = 20, + AppViewsUpdated = 21, + ViewUpdated = 30, } -impl std::default::Default for ObservableType { - fn default() -> Self { ObservableType::Unknown } +impl std::default::Default for WorkspaceObservableType { + fn default() -> Self { WorkspaceObservableType::Unknown } } pub(crate) struct ObservableSender { - ty: ObservableType, + ty: WorkspaceObservableType, subject_id: String, payload: Option>, } impl ObservableSender { - pub(crate) fn new(subject_id: &str, ty: ObservableType) -> Self { + pub(crate) fn new(subject_id: &str, ty: WorkspaceObservableType) -> Self { Self { subject_id: subject_id.to_owned(), ty, @@ -59,11 +60,11 @@ impl ObservableSender { } } -pub(crate) fn send_observable(id: &str, ty: ObservableType) { +pub(crate) fn send_observable(id: &str, ty: WorkspaceObservableType) { ObservableSender::new(id, ty).send(); } -pub(crate) fn send_observable_with_payload(id: &str, ty: ObservableType, payload: T) +pub(crate) fn send_observable_with_payload(id: &str, ty: WorkspaceObservableType, payload: T) where T: ToBytes, { diff --git a/rust-lib/flowy-workspace/src/protobuf/model/observable.rs b/rust-lib/flowy-workspace/src/protobuf/model/observable.rs index c98bdffa4c..a3f7c03ed0 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/observable.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/observable.rs @@ -24,31 +24,37 @@ // const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum ObservableType { +pub enum WorkspaceObservableType { Unknown = 0, - WorkspaceDidUpdate = 10, - AppDidUpdate = 11, + WorkspaceUpdated = 10, + AppDescUpdated = 20, + AppViewsUpdated = 21, + ViewUpdated = 30, } -impl ::protobuf::ProtobufEnum for ObservableType { +impl ::protobuf::ProtobufEnum for WorkspaceObservableType { fn value(&self) -> i32 { *self as i32 } - fn from_i32(value: i32) -> ::std::option::Option { + fn from_i32(value: i32) -> ::std::option::Option { match value { - 0 => ::std::option::Option::Some(ObservableType::Unknown), - 10 => ::std::option::Option::Some(ObservableType::WorkspaceDidUpdate), - 11 => ::std::option::Option::Some(ObservableType::AppDidUpdate), + 0 => ::std::option::Option::Some(WorkspaceObservableType::Unknown), + 10 => ::std::option::Option::Some(WorkspaceObservableType::WorkspaceUpdated), + 20 => ::std::option::Option::Some(WorkspaceObservableType::AppDescUpdated), + 21 => ::std::option::Option::Some(WorkspaceObservableType::AppViewsUpdated), + 30 => ::std::option::Option::Some(WorkspaceObservableType::ViewUpdated), _ => ::std::option::Option::None } } fn values() -> &'static [Self] { - static values: &'static [ObservableType] = &[ - ObservableType::Unknown, - ObservableType::WorkspaceDidUpdate, - ObservableType::AppDidUpdate, + static values: &'static [WorkspaceObservableType] = &[ + WorkspaceObservableType::Unknown, + WorkspaceObservableType::WorkspaceUpdated, + WorkspaceObservableType::AppDescUpdated, + WorkspaceObservableType::AppViewsUpdated, + WorkspaceObservableType::ViewUpdated, ]; values } @@ -56,38 +62,43 @@ impl ::protobuf::ProtobufEnum for ObservableType { fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new_pb_name::("ObservableType", file_descriptor_proto()) + ::protobuf::reflect::EnumDescriptor::new_pb_name::("WorkspaceObservableType", file_descriptor_proto()) }) } } -impl ::std::marker::Copy for ObservableType { +impl ::std::marker::Copy for WorkspaceObservableType { } -impl ::std::default::Default for ObservableType { +impl ::std::default::Default for WorkspaceObservableType { fn default() -> Self { - ObservableType::Unknown + WorkspaceObservableType::Unknown } } -impl ::protobuf::reflect::ProtobufValue for ObservableType { +impl ::protobuf::reflect::ProtobufValue for WorkspaceObservableType { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x10observable.proto*G\n\x0eObservableType\x12\x0b\n\x07Unknown\x10\0\ - \x12\x16\n\x12WorkspaceDidUpdate\x10\n\x12\x10\n\x0cAppDidUpdate\x10\x0b\ - J\xa5\x01\n\x06\x12\x04\0\0\x06\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\ - \n\x02\x05\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x05\0\x01\x12\x03\x02\x05\ - \x13\n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\x10\n\x0c\n\x05\x05\0\x02\0\ - \x01\x12\x03\x03\x04\x0b\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\x0e\x0f\ - \n\x0b\n\x04\x05\0\x02\x01\x12\x03\x04\x04\x1c\n\x0c\n\x05\x05\0\x02\x01\ - \x01\x12\x03\x04\x04\x16\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x04\x19\ - \x1b\n\x0b\n\x04\x05\0\x02\x02\x12\x03\x05\x04\x16\n\x0c\n\x05\x05\0\x02\ - \x02\x01\x12\x03\x05\x04\x10\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\x05\ - \x13\x15b\x06proto3\ + \n\x10observable.proto*v\n\x17WorkspaceObservableType\x12\x0b\n\x07Unkno\ + wn\x10\0\x12\x14\n\x10WorkspaceUpdated\x10\n\x12\x12\n\x0eAppDescUpdated\ + \x10\x14\x12\x13\n\x0fAppViewsUpdated\x10\x15\x12\x0f\n\x0bViewUpdated\ + \x10\x1eJ\xf7\x01\n\x06\x12\x04\0\0\x08\x01\n\x08\n\x01\x0c\x12\x03\0\0\ + \x12\n\n\n\x02\x05\0\x12\x04\x02\0\x08\x01\n\n\n\x03\x05\0\x01\x12\x03\ + \x02\x05\x1c\n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\x10\n\x0c\n\x05\x05\ + \0\x02\0\x01\x12\x03\x03\x04\x0b\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\ + \x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x04\x04\x1a\n\x0c\n\x05\x05\0\ + \x02\x01\x01\x12\x03\x04\x04\x14\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\ + \x04\x17\x19\n\x0b\n\x04\x05\0\x02\x02\x12\x03\x05\x04\x18\n\x0c\n\x05\ + \x05\0\x02\x02\x01\x12\x03\x05\x04\x12\n\x0c\n\x05\x05\0\x02\x02\x02\x12\ + \x03\x05\x15\x17\n\x0b\n\x04\x05\0\x02\x03\x12\x03\x06\x04\x19\n\x0c\n\ + \x05\x05\0\x02\x03\x01\x12\x03\x06\x04\x13\n\x0c\n\x05\x05\0\x02\x03\x02\ + \x12\x03\x06\x16\x18\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x07\x04\x15\n\x0c\ + \n\x05\x05\0\x02\x04\x01\x12\x03\x07\x04\x0f\n\x0c\n\x05\x05\0\x02\x04\ + \x02\x12\x03\x07\x12\x14b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto b/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto index 3100feddbd..2cd361a56c 100644 --- a/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto +++ b/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto @@ -1,7 +1,9 @@ syntax = "proto3"; -enum ObservableType { +enum WorkspaceObservableType { Unknown = 0; - WorkspaceDidUpdate = 10; - AppDidUpdate = 11; + WorkspaceUpdated = 10; + AppDescUpdated = 20; + AppViewsUpdated = 21; + ViewUpdated = 30; } diff --git a/rust-lib/flowy-workspace/src/services/app_controller.rs b/rust-lib/flowy-workspace/src/services/app_controller.rs index 10a9352b03..7f7096c165 100644 --- a/rust-lib/flowy-workspace/src/services/app_controller.rs +++ b/rust-lib/flowy-workspace/src/services/app_controller.rs @@ -36,7 +36,7 @@ impl AppController { let app_table = AppTable::new(params); let app: App = app_table.clone().into(); let _ = self.sql.write_app_table(app_table)?; - send_observable(&app.workspace_id, ObservableType::WorkspaceDidUpdate); + send_observable(&app.workspace_id, WorkspaceObservableType::WorkspaceUpdated); Ok(app) } @@ -49,7 +49,7 @@ impl AppController { let changeset = AppTableChangeset::new(params); let app_id = changeset.id.clone(); let _ = self.sql.update_app_table(changeset)?; - send_observable(&app_id, ObservableType::AppDidUpdate); + send_observable(&app_id, WorkspaceObservableType::AppDescUpdated); Ok(()) }