mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-08 12:07:54 -06:00
Adds change detection mechanism for document changes
This commit is contained in:
38
lib/core/notifier/document_changed_notifier.dart
Normal file
38
lib/core/notifier/document_changed_notifier.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:rxdart/subjects.dart';
|
||||
|
||||
typedef DocumentChangedCallback = void Function(DocumentModel document);
|
||||
|
||||
class DocumentChangedNotifier {
|
||||
final Subject<DocumentModel> _updated = PublishSubject();
|
||||
final Subject<DocumentModel> _deleted = PublishSubject();
|
||||
|
||||
void notifyUpdated(DocumentModel updated) {
|
||||
_updated.add(updated);
|
||||
}
|
||||
|
||||
void notifyDeleted(DocumentModel deleted) {
|
||||
_deleted.add(deleted);
|
||||
}
|
||||
|
||||
List<StreamSubscription> listen({
|
||||
DocumentChangedCallback? onUpdated,
|
||||
DocumentChangedCallback? onDeleted,
|
||||
}) {
|
||||
return [
|
||||
_updated.listen((value) {
|
||||
onUpdated?.call(value);
|
||||
}),
|
||||
_updated.listen((value) {
|
||||
onDeleted?.call(value);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
void close() {
|
||||
_updated.close();
|
||||
_deleted.close();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:rxdart/subjects.dart';
|
||||
|
||||
typedef JSON = Map<String, dynamic>;
|
||||
typedef PaperlessValidationErrors = Map<String, String>;
|
||||
typedef PaperlessLocalizedErrorMessage = String;
|
||||
|
||||
Reference in New Issue
Block a user