Revert D6264886: [IGListKit][PR] Make sure collection have unique ListDiffable objects on initial data…

Summary:
This reverts commit 5159b7989f1d17fd0a7522d986ed6abf012da77f

bypass-lint

Differential Revision: D6264886

fbshipit-source-id: 54b230fab0e7b1fdf15e065e60f4c3bfd743629b
This commit is contained in:
Ryan Nystrom 2017-11-17 12:29:49 -08:00 committed by Facebook Github Bot
parent 82a2a2ee18
commit 2f17cb5fdf
5 changed files with 10 additions and 13 deletions

View file

@ -17,8 +17,6 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag
### Fixes
- Duplicate objects for initial data source setup filtered out. [Mikhail Vashlyaev](https://github.com/yemodin) [(#993](https://github.com/Instagram/IGListKit/pull/993)
- Weakly reference the `UICollectionView` in coalescence so that it can be released if the rest of system is destroyed. [Ryan Nystrom](https://github.com/rnystrom) [(#tbd)](https://github.com/Instagram/IGListKit/pull/tbd)
- Fix bug with `-[IGListAdapter scrollToObject:supplementaryKinds:scrollDirection:scrollPosition:animated:]` where the content inset of the collection view was incorrectly being applied to the final offset. [Ryan Nystrom](https://github.com/rnystrom) [(#tbd)](https://github.com/Instagram/IGListKit/pull/tbd)

View file

@ -24,7 +24,7 @@ static NSArray *objectsWithDuplicateIdentifiersRemoved(NSArray<id<IGListDiffable
[identifiers addObject:diffIdentifier];
[uniqueObjects addObject:object];
} else {
IGLKLog(@"WARNING: Diff identifier %@ for object %@ already appeared in objects array", diffIdentifier, object);
IGLKLog(@"WARNING: Object %@ already appeared in objects array", object);
}
}
return uniqueObjects;

View file

@ -15,7 +15,6 @@
#import "IGListSectionControllerInternal.h"
#import "IGListDebugger.h"
#import "IGListArrayUtilsInternal.h"
@implementation IGListAdapter {
NSMapTable<UICollectionReusableView *, IGListSectionController *> *_viewSectionControllerMap;
@ -144,8 +143,7 @@
- (void)updateAfterPublicSettingsChange {
id<IGListAdapterDataSource> dataSource = _dataSource;
if (_collectionView != nil && dataSource != nil) {
NSArray *uniqueObjects = objectsWithDuplicateIdentifiersRemoved([dataSource objectsForListAdapter:self]);
[self updateObjects:uniqueObjects dataSource:dataSource];
[self updateObjects:[[dataSource objectsForListAdapter:self] copy] dataSource:dataSource];
}
}
@ -361,13 +359,13 @@
return;
}
NSArray *uniqueObjects = objectsWithDuplicateIdentifiersRemoved([dataSource objectsForListAdapter:self]);
NSArray *newItems = [[dataSource objectsForListAdapter:self] copy];
__weak __typeof__(self) weakSelf = self;
[self.updater reloadDataWithCollectionView:collectionView reloadUpdateBlock:^{
// purge all section controllers from the item map so that they are regenerated
[weakSelf.sectionMap reset];
[weakSelf updateObjects:uniqueObjects dataSource:dataSource];
[weakSelf updateObjects:newItems dataSource:dataSource];
} completion:^(BOOL finished) {
[weakSelf notifyDidUpdate:IGListAdapterUpdateTypeReloadData animated:NO];
if (completion) {
@ -577,8 +575,11 @@
IGParameterAssert(dataSource != nil);
#if DEBUG
NSCountedSet *identifiersSet = [NSCountedSet new];
for (id object in objects) {
[identifiersSet addObject:[object diffIdentifier]];
IGAssert([object isEqualToDiffableObject:object], @"Object instance %@ not equal to itself. This will break infra map tables.", object);
IGAssert([identifiersSet countForObject:[object diffIdentifier]] <= 1, @"Diff identifier %@ for object %@ occurs more than once. Identifiers must be unique!", [object diffIdentifier], object);
}
#endif

View file

@ -1527,11 +1527,9 @@
XCTAssertEqual(collectionView1.dataSource, adapter2);
}
- (void)test_whenPassingNonUniqueIdentifiers_adapterReloadShouldSkipDuplicates {
- (void)test_whenPassingNonUniqueIdentifiers_adapterShouldAssert {
self.dataSource.objects = @[@0, @1, @2, @0];
[self.adapter reloadDataWithCompletion:nil];
XCTAssertEqual(self.adapter.objects.count, 3);
XCTAssertThrows([self.adapter reloadDataWithCompletion:nil]);
}
- (void)test_whenPrefetchingEnabled_thatSetterDisables {

View file

@ -45,7 +45,7 @@
adapter3.collectionView = collectionView;
NSArray *descriptions = [IGListDebugger adapterDescriptions];
XCTAssertEqual(descriptions.count, 3);
XCTAssertEqual(descriptions.count, 4);
}
@end