Skip to content

Commit

Permalink
IGListBindingSectionController no longer asserts when reloading the e…
Browse files Browse the repository at this point in the history
…ntire section. (#1213)

Summary:
Issue fixed: #1174

- [X] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [X] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [X] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Pull Request resolved: #1213

Differential Revision: D9003398

Pulled By: rnystrom

fbshipit-source-id: 2c68f42e21abaea9191f26309668d866544f80b4
  • Loading branch information
jeffbailey authored and facebook-github-bot committed Jul 25, 2018
1 parent 67da3b4 commit a7d720d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag

- Added `IGListCollectionScrollingTraits` for exposing `UICollectionView` scrolling traits to section controllers via `IGListCollectionContext`. [Adam Stern](https://github.com/adamastern) (tbd)

- `IGListBindingSectionController` no longer asserts when reloading the entire section. A warning message is now logged if the entire section is going to be reloaded. [Jeff Bailey](https://github.com/jeffbailey) (#1213)

### Fixes

- Experimental fix to get the `UICollectionView` for batch updating immediately before applying the update. [Ryan Nystrom](https://github.com/rnystrom) (tbd)
Expand Down
9 changes: 6 additions & 3 deletions Source/IGListBindingSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ - (void)didUpdateToObject:(id)object {
NSArray *viewModels = [self.dataSource sectionController:self viewModelsForObject:object];
self.viewModels = objectsWithDuplicateIdentifiersRemoved(viewModels);
} else {
IGAssert([oldObject isEqualToDiffableObject:object],
@"Unequal objects %@ and %@ will cause IGListBindingSectionController to reload the entire section",
oldObject, object);
#if IGLK_LOGGING_ENABLED
if (![oldObject isEqualToDiffableObject:object]) {
IGLKLog(@"Warning: Unequal objects %@ and %@ will cause IGListBindingSectionController to reload the entire section",
oldObject, object);
}
#endif
[self updateAnimated:YES completion:nil];
}
}
Expand Down
14 changes: 12 additions & 2 deletions Tests/Objects/IGTestDiffingObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@ - (NSString *)description {
return self.key;
}

- (BOOL)isEqualToDiffableObject:(id<IGListDiffable>)object {
return YES;
- (BOOL)isEqualToDiffableObject:(id)object {
if (object == self) {
return YES;
}
if ([object isKindOfClass:[IGTestDiffingObject class]]) {
/* A simple equality test that only looks at the number of objects for the key.
It does not currently test the equality of each of the objects. */
IGTestDiffingObject *testDiffingObject = (IGTestDiffingObject *)object;
return self.objects.count == testDiffingObject.objects.count;
}

return NO;
}

@end

0 comments on commit a7d720d

Please sign in to comment.