view_repo.dart 806 B

123456789101112131415161718192021222324252627282930
  1. import 'package:app_flowy/workspace/domain/i_view.dart';
  2. import 'package:flowy_sdk/protobuf/flowy-observable/subject.pb.dart';
  3. import 'package:dartz/dartz.dart';
  4. import 'dart:async';
  5. class ViewWatchRepository {
  6. StreamSubscription<ObservableSubject>? _subscription;
  7. ViewUpdatedCallback? _updatedCallback;
  8. String viewId;
  9. ViewWatchRepository({
  10. required this.viewId,
  11. });
  12. void startWatching({
  13. ViewUpdatedCallback? updatedCallback,
  14. }) {
  15. _addViewCallback = addViewCallback;
  16. _updatedCallback = updatedCallback;
  17. _subscription = RustStreamReceiver.listen((observable) {
  18. if (observable.subjectId != appId) {
  19. return;
  20. }
  21. final ty = WorkspaceObservable.valueOf(observable.ty);
  22. if (ty != null) {
  23. _handleObservableType(ty);
  24. }
  25. });
  26. }
  27. }