FSTViewSnapshot.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <vector>
  18. #include "Firestore/core/src/firebase/firestore/core/view_snapshot.h"
  19. #include "Firestore/core/src/firebase/firestore/model/document_key_set.h"
  20. @class FSTDocument;
  21. @class FSTQuery;
  22. @class FSTDocumentSet;
  23. @class FSTViewSnapshot;
  24. NS_ASSUME_NONNULL_BEGIN
  25. typedef void (^FSTViewSnapshotHandler)(FSTViewSnapshot *_Nullable snapshot,
  26. NSError *_Nullable error);
  27. /** A view snapshot is an immutable capture of the results of a query and the changes to them. */
  28. @interface FSTViewSnapshot : NSObject
  29. - (instancetype)initWithQuery:(FSTQuery *)query
  30. documents:(FSTDocumentSet *)documents
  31. oldDocuments:(FSTDocumentSet *)oldDocuments
  32. documentChanges:
  33. (std::vector<firebase::firestore::core::DocumentViewChange>)documentChanges
  34. fromCache:(BOOL)fromCache
  35. mutatedKeys:(firebase::firestore::model::DocumentKeySet)mutatedKeys
  36. syncStateChanged:(BOOL)syncStateChanged
  37. excludesMetadataChanges:(BOOL)excludesMetadataChanges NS_DESIGNATED_INITIALIZER;
  38. - (instancetype)init NS_UNAVAILABLE;
  39. /** Returns a view snapshot as if all documents in the snapshot were added. */
  40. + (instancetype)snapshotForInitialDocuments:(FSTDocumentSet *)documents
  41. query:(FSTQuery *)query
  42. mutatedKeys:(firebase::firestore::model::DocumentKeySet)mutatedKeys
  43. fromCache:(BOOL)fromCache
  44. excludesMetadataChanges:(BOOL)excludesMetadataChanges;
  45. /** The query this view is tracking the results for. */
  46. @property(nonatomic, strong, readonly) FSTQuery *query;
  47. /** The documents currently known to be results of the query. */
  48. @property(nonatomic, strong, readonly) FSTDocumentSet *documents;
  49. /** The documents of the last snapshot. */
  50. @property(nonatomic, strong, readonly) FSTDocumentSet *oldDocuments;
  51. /** The set of changes that have been applied to the documents. */
  52. - (const std::vector<firebase::firestore::core::DocumentViewChange> &)documentChanges;
  53. /** Whether any document in the snapshot was served from the local cache. */
  54. @property(nonatomic, assign, readonly, getter=isFromCache) BOOL fromCache;
  55. /** Whether any document in the snapshot has pending local writes. */
  56. @property(nonatomic, assign, readonly) BOOL hasPendingWrites;
  57. /** Whether the sync state changed as part of this snapshot. */
  58. @property(nonatomic, assign, readonly) BOOL syncStateChanged;
  59. /** Whether this snapshot has been filtered to not include metadata changes */
  60. @property(nonatomic, assign, readonly) BOOL excludesMetadataChanges;
  61. /** The document in this snapshot that have unconfirmed writes. */
  62. @property(nonatomic, assign, readonly) firebase::firestore::model::DocumentKeySet mutatedKeys;
  63. @end
  64. NS_ASSUME_NONNULL_END