mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-23 09:18:29 +00:00
Add a flag to control how the IGSectionObject's isEqualToDiffable: is implemented
Summary: In the Feed view, all the -isEqualToDiffable: implementation only checks the pk, a.k.a the identifier. Let's mimic that behavior. Reviewed By: calimarkus Differential Revision: D18714064 fbshipit-source-id: e1fe9624da2997ecc7ca9b684ddd471d77b7564c
This commit is contained in:
parent
64f053c258
commit
d7a6fc0847
2 changed files with 32 additions and 3 deletions
|
|
@ -19,6 +19,11 @@
|
|||
|
||||
+ (instancetype)sectionWithObjects:(NSArray *)objects identifier:(NSString *)identifier;
|
||||
|
||||
/**
|
||||
@param usesIdentifierForDiffable YES if we only use the `identifier` for -isEqualToDiffableObject. NO then we compares both the `identifier` as well as `objects`.
|
||||
*/
|
||||
+ (instancetype)sectionWithObjects:(NSArray *)objects identifier:(NSString *)identifier usesIdentifierForDiffable:(BOOL)usesIdentifierForDiffable;
|
||||
|
||||
@end
|
||||
|
||||
@interface IGListTestUICollectionViewDataSource : NSObject <UICollectionViewDataSource>
|
||||
|
|
|
|||
|
|
@ -9,18 +9,26 @@
|
|||
|
||||
#import "IGListTestUICollectionViewDataSource.h"
|
||||
|
||||
#import <IGAssert/IGAssert.h>
|
||||
|
||||
@implementation IGSectionObject {
|
||||
NSString *_identifier;
|
||||
BOOL _usesIdentifierForDiffable;
|
||||
}
|
||||
|
||||
+ (instancetype)sectionWithObjects:(NSArray *)objects {
|
||||
return [IGSectionObject sectionWithObjects:objects identifier:[NSUUID UUID].UUIDString];
|
||||
return [IGSectionObject sectionWithObjects:objects identifier:[NSUUID UUID].UUIDString usesIdentifierForDiffable:NO];
|
||||
}
|
||||
|
||||
+ (instancetype)sectionWithObjects:(NSArray *)objects identifier:(NSString *)identifier {
|
||||
return [IGSectionObject sectionWithObjects:objects identifier:identifier usesIdentifierForDiffable:NO];
|
||||
}
|
||||
|
||||
+ (instancetype)sectionWithObjects:(NSArray *)objects identifier:(NSString *)identifier usesIdentifierForDiffable:(BOOL)usesIdentifierForDiffable {
|
||||
IGSectionObject *object = [[IGSectionObject alloc] init];
|
||||
object.objects = objects;
|
||||
object->_identifier = [identifier copy];
|
||||
object->_usesIdentifierForDiffable = usesIdentifierForDiffable;
|
||||
return object;
|
||||
}
|
||||
|
||||
|
|
@ -34,8 +42,24 @@
|
|||
if (object == self) {
|
||||
return YES;
|
||||
} else if ([object isKindOfClass:IGSectionObject.class]) {
|
||||
return (self.objects && [self.objects isEqualToArray:[object objects]])
|
||||
|| (!self.objects && ![object objects]);
|
||||
IGSectionObject *sectionObject = (IGSectionObject *)object;
|
||||
if (_usesIdentifierForDiffable) {
|
||||
return [_identifier isEqualToString:sectionObject->_identifier];
|
||||
} else {
|
||||
return [self isEqual:object];
|
||||
}
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:(id)object {
|
||||
if (object == self) {
|
||||
return YES;
|
||||
} else if ([object isKindOfClass:IGSectionObject.class]) {
|
||||
IGSectionObject *sectionObject = (IGSectionObject *)object;
|
||||
return ([self.objects isEqualToArray:sectionObject.objects]
|
||||
&& [_identifier isEqualToString:sectionObject->_identifier]);
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue