Files
firebase-ios-sdk/Firestore/Source/Core/FSTView.h
T
Gil 7a7eced747 Don't use using statements in Objective-C headers ... (#2827)
use namespace aliases instead.

This makes the Objective-C code much more like what it's going to end up
being like when translated to C++: headers will include classes declared
in a namespace relative to firebase::firestore so everything else will
be named relative to firebase::firestore.

Meanwhile the using statements in the headers were causing us to miss
adding using statements in source files which was moving us away from
where we wanted to be.
2019-04-12 17:03:26 -07:00

170 lines
5.8 KiB
Objective-C

/*
* 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