| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- /*
- * Copyright 2017 Google
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #import <Foundation/Foundation.h>
- #include "Firestore/core/src/firebase/firestore/core/view_snapshot.h"
- #include "Firestore/core/src/firebase/firestore/model/document_key.h"
- #include "Firestore/core/src/firebase/firestore/model/document_key_set.h"
- #include "Firestore/core/src/firebase/firestore/model/document_map.h"
- #include "Firestore/core/src/firebase/firestore/model/types.h"
- #include "absl/types/optional.h"
- @class FSTQuery;
- namespace firebase {
- namespace firestore {
- namespace remote {
- class TargetChange;
- } // namespace remote
- } // namespace firestore
- } // namespace firebase
- namespace core = firebase::firestore::core;
- namespace model = firebase::firestore::model;
- namespace remote = firebase::firestore::remote;
- NS_ASSUME_NONNULL_BEGIN
- #pragma mark - FSTViewDocumentChanges
- /** The result of applying a set of doc changes to a view. */
- @interface FSTViewDocumentChanges : NSObject
- - (instancetype)init NS_UNAVAILABLE;
- - (const model::DocumentKeySet &)mutatedKeys;
- /** The new set of docs that should be in the view. */
- - (const model::DocumentSet &)documentSet;
- /** The diff of this these docs with the previous set of docs. */
- - (const core::DocumentViewChangeSet &)changeSet;
- /**
- * Whether the set of documents passed in was not sufficient to calculate the new state of the view
- * and there needs to be another pass based on the local cache.
- */
- @property(nonatomic, assign, readonly) BOOL needsRefill;
- @end
- #pragma mark - FSTLimboDocumentChange
- typedef NS_ENUM(NSInteger, FSTLimboDocumentChangeType) {
- FSTLimboDocumentChangeTypeAdded = 0,
- FSTLimboDocumentChangeTypeRemoved,
- };
- // A change to a particular document wrt to whether it is in "limbo".
- @interface FSTLimboDocumentChange : NSObject
- + (instancetype)changeWithType:(FSTLimboDocumentChangeType)type key:(model::DocumentKey)key;
- - (id)init __attribute__((unavailable("Use a static constructor method.")));
- - (const model::DocumentKey &)key;
- @property(nonatomic, assign, readonly) FSTLimboDocumentChangeType type;
- @end
- #pragma mark - FSTViewChange
- // A set of changes to a view.
- @interface FSTViewChange : NSObject
- - (id)init __attribute__((unavailable("Use a static constructor method.")));
- - (absl::optional<core::ViewSnapshot> &)snapshot;
- @property(nonatomic, strong, readonly) NSArray<FSTLimboDocumentChange *> *limboChanges;
- @end
- #pragma mark - FSTView
- /**
- * View is responsible for computing the final merged truth of what docs are in a query. It gets
- * notified of local and remote changes to docs, and applies the query filters and limits to
- * determine the most correct possible results.
- */
- @interface FSTView : NSObject
- - (instancetype)init NS_UNAVAILABLE;
- - (instancetype)initWithQuery:(FSTQuery *)query
- remoteDocuments:(model::DocumentKeySet)remoteDocuments NS_DESIGNATED_INITIALIZER;
- /**
- * Iterates over a set of doc changes, applies the query limit, and computes what the new results
- * should be, what the changes were, and whether we may need to go back to the local cache for
- * more results. Does not make any changes to the view.
- *
- * @param docChanges The doc changes to apply to this view.
- * @return a new set of docs, changes, and refill flag.
- */
- - (FSTViewDocumentChanges *)computeChangesWithDocuments:(const model::MaybeDocumentMap &)docChanges;
- /**
- * Iterates over a set of doc changes, applies the query limit, and computes what the new results
- * should be, what the changes were, and whether we may need to go back to the local cache for
- * more results. Does not make any changes to the view.
- *
- * @param docChanges The doc changes to apply to this view.
- * @param previousChanges If this is being called with a refill, then start with this set of docs
- * and changes instead of the current view.
- * @return a new set of docs, changes, and refill flag.
- */
- - (FSTViewDocumentChanges *)computeChangesWithDocuments:(const model::MaybeDocumentMap &)docChanges
- previousChanges:
- (nullable FSTViewDocumentChanges *)previousChanges;
- /**
- * Updates the view with the given ViewDocumentChanges.
- *
- * @param docChanges The set of changes to make to the view's docs.
- * @return A new FSTViewChange with the given docs, changes, and sync state.
- */
- - (FSTViewChange *)applyChangesToDocuments:(FSTViewDocumentChanges *)docChanges;
- /**
- * Updates the view with the given FSTViewDocumentChanges and updates limbo docs and sync state from
- * the given (optional) target change.
- *
- * @param docChanges The set of changes to make to the view's docs.
- * @param targetChange A target change to apply for computing limbo docs and sync state.
- * @return A new FSTViewChange with the given docs, changes, and sync state.
- */
- - (FSTViewChange *)applyChangesToDocuments:(FSTViewDocumentChanges *)docChanges
- targetChange:
- (const absl::optional<remote::TargetChange> &)targetChange;
- /**
- * Applies an OnlineState change to the view, potentially generating an FSTViewChange if the
- * view's syncState changes as a result.
- */
- - (FSTViewChange *)applyChangedOnlineState:(model::OnlineState)onlineState;
- /**
- * The set of remote documents that the server has told us belongs to the target associated with
- * this view.
- */
- - (const model::DocumentKeySet &)syncedDocuments;
- @end
- NS_ASSUME_NONNULL_END
|