Skip to content

Commit 3095515

Browse files
committed
decouple data source from FUIArray
1 parent 546c7bf commit 3095515

File tree

7 files changed

+14
-22
lines changed

7 files changed

+14
-22
lines changed

FirebaseDatabaseUI/FUICollectionViewDataSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ NS_ASSUME_NONNULL_BEGIN
6767
NSIndexPath *indexPath,
6868
FIRDataSnapshot *object))populateCell NS_DESIGNATED_INITIALIZER;
6969

70-
- (instancetype)initWithArray:(FUIArray *)array NS_UNAVAILABLE;
70+
- (instancetype)initWithCollection:(id<FUICollection>)collection NS_UNAVAILABLE;
7171

7272
@end
7373

FirebaseDatabaseUI/FUICollectionViewDataSource.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ - (instancetype)initWithQuery:(FIRDatabaseQuery *)query
3232
NSIndexPath *,
3333
FIRDataSnapshot *))populateCell {
3434
FUIArray *array = [[FUIArray alloc] initWithQuery:query];
35-
self = [super initWithArray:array];
35+
self = [super initWithCollection:array];
3636
if (self) {
3737
_collectionView = collectionView;
3838
_populateCellAtIndexPath = populateCell;

FirebaseDatabaseUI/FUIDataSource.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*/
4545
@property (nonatomic, readonly) NSUInteger count;
4646

47-
- (instancetype)initWithArray:(FUIArray *)array NS_DESIGNATED_INITIALIZER;
47+
- (instancetype)initWithCollection:(id<FUICollection>)collection NS_DESIGNATED_INITIALIZER;
4848

4949
- (instancetype)init NS_UNAVAILABLE;
5050

@@ -53,11 +53,6 @@
5353
*/
5454
- (FIRDataSnapshot *)objectAtIndex:(NSUInteger)index;
5555

56-
/**
57-
* Pass through of [FirebaseArray refForIndex:].
58-
*/
59-
- (FIRDatabaseReference *)refForIndex:(NSUInteger)index;
60-
6156
/**
6257
* Provides a block which is called when the backing array cancels its query.
6358
* @param block the block

FirebaseDatabaseUI/FUIDataSource.m

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,36 @@ @interface FUIDataSource ()
2727
/**
2828
* The FirebaseArray which backs the instance of the datasource.
2929
*/
30-
@property(strong, nonatomic, nonnull) FUIArray *array;
30+
@property(strong, nonatomic, nonnull) id<FUICollection> collection;
3131

3232
@end
3333

3434
@implementation FUIDataSource
3535

3636
#pragma mark - Initializer methods
3737

38-
- (instancetype)initWithArray:(FUIArray *)array {
38+
- (instancetype)initWithCollection:(id<FUICollection>)collection {
3939
self = [super init];
4040
if (self) {
41-
_array = array;
42-
_array.delegate = self;
43-
[array observeQuery];
41+
_collection = collection;
42+
_collection.delegate = self;
43+
[_collection observeQuery];
4444
}
4545
return self;
4646
}
4747

4848
#pragma mark - API methods
4949

5050
- (NSArray *)items {
51-
return [self.array.items copy];
51+
return [self.collection.items copy];
5252
}
5353

5454
- (NSUInteger)count {
55-
return self.array.count;
55+
return self.collection.count;
5656
}
5757

5858
- (FIRDataSnapshot *)objectAtIndex:(NSUInteger)index {
59-
return [self.array snapshotAtIndex:index];
60-
}
61-
62-
- (FIRDatabaseReference *)refForIndex:(NSUInteger)index {
63-
return [self.array refForIndex:index];
59+
return [self.collection snapshotAtIndex:index];
6460
}
6561

6662
- (void)cancelWithBlock:(void (^)(NSError *))block {

FirebaseDatabaseUI/FUITableViewDataSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN
6363
NSIndexPath *indexPath,
6464
FIRDataSnapshot *object))populateCell NS_DESIGNATED_INITIALIZER;
6565

66-
- (instancetype)initWithArray:(FUIArray *)array NS_UNAVAILABLE;
66+
- (instancetype)initWithCollection:(id<FUICollection>)collection NS_UNAVAILABLE;
6767

6868
@end
6969

FirebaseDatabaseUI/FUITableViewDataSource.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ - (instancetype)initWithQuery:(FIRDatabaseQuery *)query
4141
NSIndexPath *,
4242
FIRDataSnapshot *))populateCell {
4343
FUIArray *array = [[FUIArray alloc] initWithQuery:query];
44-
self = [super initWithArray:array];
44+
self = [super initWithCollection:array];
4545
if (self) {
4646
self.tableView = tableView;
4747
self.populateCell = populateCell;

FirebaseDatabaseUITests/FUIArrayTest.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ - (void)setUp {
4141
self.observable = [[FUITestObservable alloc] init];
4242
self.firebaseArray = [[FUIArray alloc] initWithQuery:self.observable];
4343
self.firebaseArray.delegate = self.arrayDelegate;
44+
[self.firebaseArray observeQuery];
4445
}
4546

4647
- (void)tearDown {

0 commit comments

Comments
 (0)