Skip to content

Commit 8828e5b

Browse files
committed
simplify object ownership graph and update doc comments
1 parent 470ae9e commit 8828e5b

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

FirebaseDatabaseUI/FirebaseIndexArray.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ NS_ASSUME_NONNULL_BEGIN
2525
@class FirebaseIndexArray;
2626

2727
/**
28-
* A protocol to allow instances of FirebaseArray to raise events through a
29-
* delegate. Raises all
30-
* Firebase events except FIRDataEventTypeValue.
28+
* A protocol to allow instances of FirebaseIndexArray to raise events through a
29+
* delegate. Raises all Firebase events except @c FIRDataEventTypeValue.
3130
*/
32-
@protocol FirebaseIndexArrayDelegate<NSObject>
31+
@protocol FirebaseIndexArrayDelegate <NSObject>
3332

3433
@optional
3534

FirebaseDatabaseUI/FirebaseIndexArray.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ @interface FirebaseIndexArray () <FirebaseArrayDelegate>
3232

3333
@end
3434

35+
/**
36+
* FirebaseIndexArray manages an instance of FirebaseArray internally to
37+
* keep track of which queries it should be updating. The FirebaseArrayDelegate
38+
* methods are responsible for keeping observers up-to-date as the contents of
39+
* the FirebaseArray change.
40+
*/
3541
@implementation FirebaseIndexArray
3642

3743
- (instancetype)init {
@@ -101,12 +107,6 @@ - (void)dealloc {
101107

102108
#pragma mark - FirebaseArrayDelegate
103109

104-
// These delegate methods are entirely responsible
105-
// for keeping a local array of queries up to date.
106-
// Like mapping a FirebaseArray's contents, except
107-
// they must be kept up to date as the FirebaseArray
108-
// changes over time.
109-
110110
- (void)observer:(FirebaseQueryObserver *)obs
111111
didFinishLoadWithSnap:(FIRDataSnapshot *)snap
112112
error:(NSError *)error {
@@ -130,11 +130,12 @@ - (void)array:(FirebaseArray *)array
130130
atIndex:(NSUInteger)index {
131131
NSParameterAssert([object.key isKindOfClass:[NSString class]]);
132132
id<FIRDataObservable> query = [self.data child:object.key];
133+
__weak typeof(self) wSelf = self;
133134
FirebaseQueryObserver *obs = [FirebaseQueryObserver observerForQuery:query
134135
completion:^(FirebaseQueryObserver *observer,
135136
FIRDataSnapshot *snap,
136137
NSError *error) {
137-
[self observer:observer didFinishLoadWithSnap:snap error:error];
138+
[wSelf observer:observer didFinishLoadWithSnap:snap error:error];
138139
}];
139140
[self.observers insertObject:obs atIndex:index];
140141

@@ -167,12 +168,13 @@ - (void)array:(FirebaseArray *)array
167168
[self.observers[index] removeAllObservers];
168169

169170
// Add new observer
171+
__weak typeof(self) wSelf = self;
170172
id<FIRDataObservable> query = [self.data child:object.key];
171173
FirebaseQueryObserver *obs = [FirebaseQueryObserver observerForQuery:query
172174
completion:^(FirebaseQueryObserver *observer,
173175
FIRDataSnapshot *snap,
174176
NSError *error) {
175-
[self observer:observer didFinishLoadWithSnap:snap error:error];
177+
[wSelf observer:observer didFinishLoadWithSnap:snap error:error];
176178
}];
177179
[self.observers replaceObjectAtIndex:index withObject:obs];
178180

0 commit comments

Comments
 (0)