Skip to content

expose FUIIndexArray's indexes in data sources #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,18 @@ didFailLoadAtIndex:(NSUInteger)index
*/
@interface FUIIndexCollectionViewDataSource : NSObject <UICollectionViewDataSource>

/**
* The delegate that should receive updates from this data source. Implement this delegate
* to handle load errors and successes.
*/
@property (nonatomic, readwrite, weak, nullable) id<FUIIndexCollectionViewDataSourceDelegate> delegate;

/**
* The indexes that have finished loading in the data source. Returns an empty array if no indexes
* have loaded.
*/
@property (nonatomic, readonly, copy) NSArray<FIRDataSnapshot *> *indexes;

- (instancetype)init NS_UNAVAILABLE;

/**
Expand Down
4 changes: 4 additions & 0 deletions FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
return self;
}

- (NSArray<FIRDataSnapshot *> *)indexes {
return self.array.indexes;
}

#pragma mark - FUIIndexArrayDelegate

- (void)array:(FUIIndexArray *)array
Expand Down
9 changes: 8 additions & 1 deletion FirebaseDatabaseUI/FUIIndexTableViewDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,17 @@ didFailLoadAtIndex:(NSUInteger)index
@interface FUIIndexTableViewDataSource : NSObject <UITableViewDataSource>

/**
* The delegate that will receive events from this data source.
* The delegate that should receive updates from this data source. Implement this delegate
* to handle load errors and successes.
*/
@property (nonatomic, readwrite, weak, nullable) id<FUIIndexTableViewDataSourceDelegate> delegate;

/**
* The indexes that have finished loading in the data source. Returns an empty array if no indexes
* have loaded.
*/
@property (nonatomic, readonly, copy) NSArray<FIRDataSnapshot *> *indexes;

- (instancetype)init NS_UNAVAILABLE;

/**
Expand Down
4 changes: 4 additions & 0 deletions FirebaseDatabaseUI/FUIIndexTableViewDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ - (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
return self;
}

- (NSArray<FIRDataSnapshot *> *)indexes {
return self.array.indexes;
}

#pragma mark - FUIIndexArrayDelegate

- (void)array:(FUIIndexArray *)array
Expand Down
12 changes: 12 additions & 0 deletions FirebaseDatabaseUITests/FUIIndexCollectionViewDataSourceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ - (void)tearDown {
[super tearDown];
}

- (void)testItReturnsItsArraysIndexes {
NSArray *expectedIndexes = @[
[FUIFakeSnapshot snapWithKey:@"1" value:@(YES)],
[FUIFakeSnapshot snapWithKey:@"2" value:@(YES)],
[FUIFakeSnapshot snapWithKey:@"3" value:@(YES)],
];

NSArray *indexes = self.dataSource.indexes;

XCTAssert([indexes isEqual:expectedIndexes], @"expected data source's indexes to equal its array's indexes");
}

- (void)testItPopulatesCells {
UICollectionViewCell *cell = [self.dataSource collectionView:self.collectionView
cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
Expand Down
12 changes: 12 additions & 0 deletions FirebaseDatabaseUITests/FUIIndexTableViewDataSourceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ - (void)tearDown {
[super tearDown];
}

- (void)testItReturnsItsArraysIndexes {
NSArray *expectedIndexes = @[
[FUIFakeSnapshot snapWithKey:@"1" value:@(YES)],
[FUIFakeSnapshot snapWithKey:@"2" value:@(YES)],
[FUIFakeSnapshot snapWithKey:@"3" value:@(YES)],
];

NSArray *indexes = self.dataSource.indexes;

XCTAssert([indexes isEqual:expectedIndexes], @"expected data source's indexes to equal its array's indexes");
}

- (void)testItPopulatesCells {
UITableViewCell *cell = [self.dataSource tableView:self.tableView
cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
Expand Down