From 33b12f6c70729d56c6e6350d435559cec1c44c61 Mon Sep 17 00:00:00 2001 From: Gil Date: Sat, 14 Apr 2018 17:19:06 -0700 Subject: Replace `DocumentListenOptions` with a simple boolean. (#1099) * Replace `DocumentListenOptions` with a simple boolean. Instead of calling `addSnapshotListener(options: DocumentListenOptions.includeMetadataChanges(true))` call `addSnapshotListener(includeMetadataChanges:true)` * Style --- Firestore/Source/API/FIRDocumentReference.mm | 66 +++++++--------------------- 1 file changed, 15 insertions(+), 51 deletions(-) (limited to 'Firestore/Source/API') diff --git a/Firestore/Source/API/FIRDocumentReference.mm b/Firestore/Source/API/FIRDocumentReference.mm index 9fb4541..d3a9295 100644 --- a/Firestore/Source/API/FIRDocumentReference.mm +++ b/Firestore/Source/API/FIRDocumentReference.mm @@ -52,40 +52,6 @@ using firebase::firestore::model::ResourcePath; NS_ASSUME_NONNULL_BEGIN -#pragma mark - FIRDocumentListenOptions - -@interface FIRDocumentListenOptions () - -- (instancetype)initWithIncludeMetadataChanges:(BOOL)includeMetadataChanges - NS_DESIGNATED_INITIALIZER; - -@property(nonatomic, assign, readonly) BOOL includeMetadataChanges; - -@end - -@implementation FIRDocumentListenOptions - -+ (instancetype)options { - return [[FIRDocumentListenOptions alloc] init]; -} - -- (instancetype)initWithIncludeMetadataChanges:(BOOL)includeMetadataChanges { - if (self = [super init]) { - _includeMetadataChanges = includeMetadataChanges; - } - return self; -} - -- (instancetype)init { - return [self initWithIncludeMetadataChanges:NO]; -} - -- (instancetype)includeMetadataChanges:(BOOL)includeMetadataChanges { - return [[FIRDocumentListenOptions alloc] initWithIncludeMetadataChanges:includeMetadataChanges]; -} - -@end - #pragma mark - FIRDocumentReference @interface FIRDocumentReference () @@ -198,10 +164,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)getDocumentWithCompletion:(void (^)(FIRDocumentSnapshot *_Nullable document, NSError *_Nullable error))completion { - FSTListenOptions *listenOptions = - [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES - includeDocumentMetadataChanges:YES - waitForSyncWhenOnline:YES]; + FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES + includeDocumentMetadataChanges:YES + waitForSyncWhenOnline:YES]; dispatch_semaphore_t registered = dispatch_semaphore_create(0); __block id listenerRegistration; @@ -238,20 +203,20 @@ NS_ASSUME_NONNULL_BEGIN } }; - listenerRegistration = - [self addSnapshotListenerInternalWithOptions:listenOptions listener:listener]; + listenerRegistration = [self addSnapshotListenerInternalWithOptions:options listener:listener]; dispatch_semaphore_signal(registered); } - (id)addSnapshotListener:(FIRDocumentSnapshotBlock)listener { - return [self addSnapshotListenerWithOptions:nil listener:listener]; + return [self addSnapshotListenerWithIncludeMetadataChanges:NO listener:listener]; } -- (id)addSnapshotListenerWithOptions: - (nullable FIRDocumentListenOptions *)options - listener:(FIRDocumentSnapshotBlock)listener { - return [self addSnapshotListenerInternalWithOptions:[self internalOptions:options] - listener:listener]; +- (id) +addSnapshotListenerWithIncludeMetadataChanges:(BOOL)includeMetadataChanges + listener:(FIRDocumentSnapshotBlock)listener { + FSTListenOptions *options = + [self internalOptionsForIncludeMetadataChanges:includeMetadataChanges]; + return [self addSnapshotListenerInternalWithOptions:options listener:listener]; } - (id) @@ -291,11 +256,10 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions } /** Converts the public API options object to the internal options object. */ -- (FSTListenOptions *)internalOptions:(nullable FIRDocumentListenOptions *)options { - return - [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:options.includeMetadataChanges - includeDocumentMetadataChanges:options.includeMetadataChanges - waitForSyncWhenOnline:NO]; +- (FSTListenOptions *)internalOptionsForIncludeMetadataChanges:(BOOL)includeMetadataChanges { + return [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:includeMetadataChanges + includeDocumentMetadataChanges:includeMetadataChanges + waitForSyncWhenOnline:NO]; } @end -- cgit v1.2.3