File tree Expand file tree Collapse file tree 4 files changed +14
-5
lines changed Expand file tree Collapse file tree 4 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,6 @@ - (instancetype)initWithQuery:(FIRDatabaseQuery *)query delegate:(id<FUICollecti
47
47
self.query = query;
48
48
self.handles = [NSMutableSet setWithCapacity: 4 ];
49
49
self.delegate = delegate;
50
- [self initListeners ];
51
50
}
52
51
return self;
53
52
}
@@ -63,14 +62,13 @@ + (instancetype)arrayWithQuery:(id<FUIDataObservable>)query {
63
62
#pragma mark - Memory management methods
64
63
65
64
- (void )dealloc {
66
- for (NSNumber *handle in _handles) {
67
- [_query removeObserverWithHandle: handle.unsignedIntegerValue];
68
- }
65
+ [self invalidate ];
69
66
}
70
67
71
68
#pragma mark - Private API methods
72
69
73
- - (void )initListeners {
70
+ - (void )observeQuery {
71
+ if (self.handles .count == 4 ) { /* don't duplicate observers */ return ; }
74
72
FIRDatabaseHandle handle;
75
73
handle = [self .query observeEventType: FIRDataEventTypeChildAdded
76
74
andPreviousSiblingKeyWithBlock: ^(FIRDataSnapshot *snapshot, NSString *previousChildKey) {
@@ -153,6 +151,12 @@ - (void)initListeners {
153
151
[_handles addObject: @(handle)];
154
152
}
155
153
154
+ - (void )invalidate {
155
+ for (NSNumber *handle in _handles) {
156
+ [_query removeObserverWithHandle: handle.unsignedIntegerValue];
157
+ }
158
+ }
159
+
156
160
- (NSUInteger )indexForKey : (NSString *)key {
157
161
NSParameterAssert (key != nil );
158
162
Original file line number Diff line number Diff line change @@ -38,6 +38,9 @@ NS_ASSUME_NONNULL_BEGIN
38
38
39
39
- (FIRDataSnapshot *)snapshotAtIndex : (NSInteger )index ;
40
40
41
+ - (void )observeQuery ;
42
+ - (void )invalidate ;
43
+
41
44
@end
42
45
43
46
/* *
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ - (instancetype)initWithArray:(FUIArray *)array {
40
40
if (self) {
41
41
_array = array;
42
42
_array.delegate = self;
43
+ [array observeQuery ];
43
44
}
44
45
return self;
45
46
}
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ - (void)dealloc {
63
63
}
64
64
65
65
- (void )observeQuery {
66
+ if (self.handles .count == 4 ) { /* don't duplicate observers */ return ; }
66
67
FIRDatabaseHandle handle;
67
68
handle = [self .query observeEventType: FIRDataEventTypeChildAdded
68
69
andPreviousSiblingKeyWithBlock: ^(FIRDataSnapshot *snapshot, NSString *previousChildKey) {
You can’t perform that action at this time.
0 commit comments