mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-24 09:48:21 +00:00
remove duplicate identifiers from IGListBindingSectionController objects
Summary: I was building a new `IGListBindingSectionController` subclass and accidentally used two view models with the same ID. Was seeing strange results and realized we're not removing dups or asserting here. Adding a call to `objectsWithDuplicateIdentifiersRemoved` when the view models are first requested. Reviewed By: rnystrom Differential Revision: D8303601 fbshipit-source-id: 42c62adc401feaec2c7dce2a83cfc6533599752b
This commit is contained in:
parent
0796e92a09
commit
a1ee4c19f7
3 changed files with 27 additions and 8 deletions
|
|
@ -16,6 +16,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag
|
||||||
|
|
||||||
- `[IGListAdapterUpdater performBatchUpdatesWithCollectionViewBlock:]` and `[IGListAdapterUpdater performReloadDataWithCollectionViewBlock:]` clean state and run completion blocks if their `UICollectionView` is nil. [Brandon Darin](https://github.com/jbd1030) (tbd)
|
- `[IGListAdapterUpdater performBatchUpdatesWithCollectionViewBlock:]` and `[IGListAdapterUpdater performReloadDataWithCollectionViewBlock:]` clean state and run completion blocks if their `UICollectionView` is nil. [Brandon Darin](https://github.com/jbd1030) (tbd)
|
||||||
|
|
||||||
|
- Ensuring view models with duplicate diff identifiers are removed when view models are first requested by `IGListBindingSectionController` [Adam Stern](https://github.com/adamastern) (tbd)
|
||||||
|
|
||||||
3.4.0
|
3.4.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,8 @@ typedef NS_ENUM(NSInteger, IGListDiffingSectionState) {
|
||||||
self.object = object;
|
self.object = object;
|
||||||
|
|
||||||
if (oldObject == nil) {
|
if (oldObject == nil) {
|
||||||
self.viewModels = [[self.dataSource sectionController:self viewModelsForObject:object] copy];
|
NSArray *viewModels = [self.dataSource sectionController:self viewModelsForObject:object];
|
||||||
|
self.viewModels = objectsWithDuplicateIdentifiersRemoved(viewModels);
|
||||||
} else {
|
} else {
|
||||||
IGAssert([oldObject isEqualToDiffableObject:object],
|
IGAssert([oldObject isEqualToDiffableObject:object],
|
||||||
@"Unequal objects %@ and %@ will cause IGListBindingSectionController to reload the entire section",
|
@"Unequal objects %@ and %@ will cause IGListBindingSectionController to reload the entire section",
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,19 @@
|
||||||
XCTAssertEqualObjects(cell12.textField.text, @"42");
|
XCTAssertEqualObjects(cell12.textField.text, @"42");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)test_withDuplicateDiffIdentifiers_thatDuplicatesAreRemoved {
|
||||||
|
[self setupWithObjects:@[
|
||||||
|
[[IGTestDiffingObject alloc] initWithKey:@1 objects:@[@7, @7]],
|
||||||
|
]];
|
||||||
|
|
||||||
|
XCTAssertEqual([self.collectionView numberOfSections], 1);
|
||||||
|
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 1);
|
||||||
|
|
||||||
|
IGTestNumberBindableCell *cell00 = [self cellAtSection:0 item:0];
|
||||||
|
|
||||||
|
XCTAssertEqualObjects(cell00.textField.text, @"7");
|
||||||
|
}
|
||||||
|
|
||||||
- (void)test_whenUpdating_withAddedModels_thatCellsCorrectAndConfigured {
|
- (void)test_whenUpdating_withAddedModels_thatCellsCorrectAndConfigured {
|
||||||
[self setupWithObjects:@[
|
[self setupWithObjects:@[
|
||||||
[[IGTestDiffingObject alloc] initWithKey:@1 objects:@[@7, @"seven"]],
|
[[IGTestDiffingObject alloc] initWithKey:@1 objects:@[@7, @"seven"]],
|
||||||
|
|
@ -362,21 +375,24 @@
|
||||||
|
|
||||||
- (void)test_whenUpdating_withMutableArrayObject_thatViewModelsDontMutate {
|
- (void)test_whenUpdating_withMutableArrayObject_thatViewModelsDontMutate {
|
||||||
NSArray *objects = @[
|
NSArray *objects = @[
|
||||||
@"foo",
|
@"foo",
|
||||||
@"bar"
|
@"bar"
|
||||||
];
|
];
|
||||||
|
|
||||||
NSMutableArray *initObjects = [NSMutableArray arrayWithArray:objects];
|
NSMutableArray *initObjects = [NSMutableArray arrayWithArray:objects];
|
||||||
|
|
||||||
[self setupWithObjects:@[
|
[self setupWithObjects:@[
|
||||||
[[IGTestDiffingObject alloc] initWithKey:@1 objects:initObjects]
|
[[IGTestDiffingObject alloc] initWithKey:@1 objects:initObjects]
|
||||||
]];
|
]];
|
||||||
|
|
||||||
IGTestDiffingSectionController *section = [self.adapter sectionControllerForObject:self.dataSource.objects.firstObject];
|
IGTestDiffingSectionController *section = [self.adapter sectionControllerForObject:self.dataSource.objects.firstObject];
|
||||||
|
|
||||||
NSArray *oldModels = [section.viewModels copy];
|
XCTAssertNotEqual(initObjects, section.viewModels);
|
||||||
|
XCTAssertEqualObjects(initObjects, section.viewModels);
|
||||||
|
|
||||||
[initObjects removeAllObjects];
|
[initObjects removeAllObjects];
|
||||||
|
|
||||||
XCTAssertEqual(oldModels, section.viewModels);
|
XCTAssertNotEqualObjects(initObjects, section.viewModels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue