FSTViewSnapshot.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #include "Firestore/core/src/firebase/firestore/core/view_snapshot.h"
  18. #include "Firestore/core/src/firebase/firestore/model/document_key_set.h"
  19. using firebase::firestore::model::DocumentKeySet;
  20. @class FSTDocument;
  21. @class FSTQuery;
  22. @class FSTDocumentSet;
  23. @class FSTViewSnapshot;
  24. NS_ASSUME_NONNULL_BEGIN
  25. #pragma mark - FSTDocumentViewChange
  26. /** A change to a single document's state within a view. */
  27. @interface FSTDocumentViewChange : NSObject
  28. - (id)init __attribute__((unavailable("Use a static constructor method.")));
  29. + (instancetype)changeWithDocument:(FSTDocument *)document
  30. type:(firebase::firestore::core::DocumentViewChangeType)type;
  31. /** The type of change for the document. */
  32. @property(nonatomic, assign, readonly) firebase::firestore::core::DocumentViewChangeType type;
  33. /** The document whose status changed. */
  34. @property(nonatomic, strong, readonly) FSTDocument *document;
  35. @end
  36. #pragma mark - FSTDocumentChangeSet
  37. /** The possibly states a document can be in w.r.t syncing from local storage to the backend. */
  38. typedef NS_ENUM(NSInteger, FSTSyncState) {
  39. FSTSyncStateNone = 0,
  40. FSTSyncStateLocal,
  41. FSTSyncStateSynced,
  42. };
  43. /** A set of changes to documents with respect to a view. This set is mutable. */
  44. @interface FSTDocumentViewChangeSet : NSObject
  45. /** Returns a new empty change set. */
  46. + (instancetype)changeSet;
  47. /** Takes a new change and applies it to the set. */
  48. - (void)addChange:(FSTDocumentViewChange *)change;
  49. /** Returns the set of all changes tracked in this set. */
  50. - (NSArray<FSTDocumentViewChange *> *)changes;
  51. @end
  52. #pragma mark - FSTViewSnapshot
  53. typedef void (^FSTViewSnapshotHandler)(FSTViewSnapshot *_Nullable snapshot,
  54. NSError *_Nullable error);
  55. /** A view snapshot is an immutable capture of the results of a query and the changes to them. */
  56. @interface FSTViewSnapshot : NSObject
  57. - (instancetype)initWithQuery:(FSTQuery *)query
  58. documents:(FSTDocumentSet *)documents
  59. oldDocuments:(FSTDocumentSet *)oldDocuments
  60. documentChanges:(NSArray<FSTDocumentViewChange *> *)documentChanges
  61. fromCache:(BOOL)fromCache
  62. mutatedKeys:(DocumentKeySet)mutatedKeys
  63. syncStateChanged:(BOOL)syncStateChanged
  64. excludesMetadataChanges:(BOOL)excludesMetadataChanges NS_DESIGNATED_INITIALIZER;
  65. - (instancetype)init NS_UNAVAILABLE;
  66. /** Returns a view snapshot as if all documents in the snapshot were added. */
  67. + (instancetype)snapshotForInitialDocuments:(FSTDocumentSet *)documents
  68. query:(FSTQuery *)query
  69. mutatedKeys:(DocumentKeySet)mutatedKeys
  70. fromCache:(BOOL)fromCache
  71. excludesMetadataChanges:(BOOL)excludesMetadataChanges;
  72. /** The query this view is tracking the results for. */
  73. @property(nonatomic, strong, readonly) FSTQuery *query;
  74. /** The documents currently known to be results of the query. */
  75. @property(nonatomic, strong, readonly) FSTDocumentSet *documents;
  76. /** The documents of the last snapshot. */
  77. @property(nonatomic, strong, readonly) FSTDocumentSet *oldDocuments;
  78. /** The set of changes that have been applied to the documents. */
  79. @property(nonatomic, strong, readonly) NSArray<FSTDocumentViewChange *> *documentChanges;
  80. /** Whether any document in the snapshot was served from the local cache. */
  81. @property(nonatomic, assign, readonly, getter=isFromCache) BOOL fromCache;
  82. /** Whether any document in the snapshot has pending local writes. */
  83. @property(nonatomic, assign, readonly) BOOL hasPendingWrites;
  84. /** Whether the sync state changed as part of this snapshot. */
  85. @property(nonatomic, assign, readonly) BOOL syncStateChanged;
  86. /** Whether this snapshot has been filtered to not include metadata changes */
  87. @property(nonatomic, assign, readonly) BOOL excludesMetadataChanges;
  88. /** The document in this snapshot that have unconfirmed writes. */
  89. @property(nonatomic, assign, readonly) DocumentKeySet mutatedKeys;
  90. @end
  91. NS_ASSUME_NONNULL_END