clean up performExperimentalUpdateAnimated

Summary:
Lets clean up `-performExperimentalUpdateAnimated`
* Remove the "experimental"
* Re-order the params to match the other method
* Rename dataBlock -> sectionDataBlock to make it clear we mean sections
* Rename applyDataBlock -> applySectionDataBlock

Reviewed By: Haud

Differential Revision: D25884784

fbshipit-source-id: e24c54b43c08c02538c83ba044b1a547cd0f38ae
This commit is contained in:
Maxime Ollivier 2021-01-21 19:55:59 -08:00 committed by Facebook GitHub Bot
parent 43af8838df
commit 9994d5abc2
9 changed files with 251 additions and 251 deletions

View file

@ -350,7 +350,7 @@
[self _enterBatchUpdates];
__weak __typeof__(self) weakSelf = self;
IGListTransitionDataBlock dataBlock = ^IGListTransitionData *{
IGListTransitionDataBlock sectionDataBlock = ^IGListTransitionData *{
__typeof__(self) strongSelf = weakSelf;
if (strongSelf == nil) {
return nil;
@ -359,7 +359,7 @@
return [strongSelf _generateTransitionDataWithObjects:toObjects dataSource:dataSource];
};
IGListTransitionDataApplyBlock applyDataBlock = ^void(IGListTransitionData *data) {
IGListTransitionDataApplyBlock applySectionDataBlock = ^void(IGListTransitionData *data) {
__typeof__(self) strongSelf = weakSelf;
if (strongSelf == nil) {
return;
@ -384,11 +384,11 @@
[strongSelf _exitBatchUpdates];
};
[updater performExperimentalUpdateAnimated:animated
collectionViewBlock:[self _collectionViewBlock]
dataBlock:dataBlock
applyDataBlock:applyDataBlock
completion:outerCompletionBlock];
[updater performUpdateWithCollectionViewBlock:[self _collectionViewBlock]
animated:animated
sectionDataBlock:sectionDataBlock
applySectionDataBlock:applySectionDataBlock
completion:outerCompletionBlock];
}
- (void)reloadDataWithCompletion:(nullable IGListUpdaterCompletion)completion {

View file

@ -63,7 +63,7 @@
// dispatch_async to give the main queue time to collect more batch updates so that a minimum amount of work
// (diffing, etc) is done on main. dispatch_async does not garauntee a full runloop turn will pass though.
// see -performUpdateWithCollectionView:fromObjects:toObjects:animated:objectTransitionBlock:completion: for more
// see -performUpdateWithCollectionViewBlock:animated:sectionDataBlock:applySectionDataBlock:completion: for more
// details on how coalescence is done.
self.hasQueuedUpdate = YES;
dispatch_async(dispatch_get_main_queue(), ^{
@ -147,21 +147,21 @@ static NSUInteger IGListIdentifierHash(const void *item, NSUInteger (*size)(cons
return functions;
}
- (void)performExperimentalUpdateAnimated:(BOOL)animated
collectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock
dataBlock:(IGListTransitionDataBlock)dataBlock
applyDataBlock:(IGListTransitionDataApplyBlock)applyDataBlock
completion:(IGListUpdatingCompletion)completion {
- (void)performUpdateWithCollectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock
animated:(BOOL)animated
sectionDataBlock:(IGListTransitionDataBlock)sectionDataBlock
applySectionDataBlock:(IGListTransitionDataApplyBlock)applySectionDataBlock
completion:(nullable IGListUpdatingCompletion)completion {
IGAssertMainThread();
IGParameterAssert(collectionViewBlock != nil);
IGParameterAssert(dataBlock != nil);
IGParameterAssert(applyDataBlock != nil);
IGParameterAssert(sectionDataBlock != nil);
IGParameterAssert(applySectionDataBlock != nil);
[self.transactionBuilder addSectionBatchUpdateAnimated:animated
collectionViewBlock:collectionViewBlock
dataBlock:dataBlock
applyDataBlock:applyDataBlock
completion:completion];
collectionViewBlock:collectionViewBlock
sectionDataBlock:sectionDataBlock
applySectionDataBlock:applySectionDataBlock
completion:completion];
[self _queueUpdateIfNeeded];
}

View file

@ -15,14 +15,14 @@
return [NSPointerFunctions pointerFunctionsWithOptions:NSPointerFunctionsObjectPersonality];
}
- (void)performExperimentalUpdateAnimated:(BOOL)animated
collectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock
dataBlock:(IGListTransitionDataBlock)dataBlock
applyDataBlock:(IGListTransitionDataApplyBlock)applyDataBlock
completion:(nullable IGListUpdatingCompletion)completion {
IGListTransitionData *sectionData = dataBlock ? dataBlock() : nil;
if (sectionData != nil) {
applyDataBlock(sectionData);
- (void)performUpdateWithCollectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock
animated:(BOOL)animated
sectionDataBlock:(IGListTransitionDataBlock)sectionDataBlock
applySectionDataBlock:(IGListTransitionDataApplyBlock)applySectionDataBlock
completion:(nullable IGListUpdatingCompletion)completion {
IGListTransitionData *sectionData = sectionDataBlock ? sectionDataBlock() : nil;
if (sectionData != nil && applySectionDataBlock != nil) {
applySectionDataBlock(sectionData);
}
[self _synchronousReloadDataWithCollectionView:collectionViewBlock()];
if (completion) {

View file

@ -84,24 +84,24 @@ NS_SWIFT_NAME(ListUpdatingDelegate)
/**
Perform a **section** update from an old array of objects to a new one.
@param animated A flag indicating if the transition should be animated.
@param collectionViewBlock A block returning the collecion view to perform updates on.
@param dataBlock A block that returns the section information (ex: from and to objects)
@param applyDataBlock A block that must be called when the adapter applies changes to the collection view.
@param animated A flag indicating if the transition should be animated.
@param sectionDataBlock A block that returns the section information (ex: from and to objects)
@param applySectionDataBlock A block that must be called when the adapter applies changes to the collection view.
@param completion A completion block to execute when the update is finished.
@note Implementations determine how to transition between objects. You can perform a diff on the objects, reload
each section, or simply call `-reloadData` on the collection view. In the end, the collection view must be setup with a
section for each object in the `toObjects` array.
The `applyDataBlock` block should be called prior to making any `UICollectionView` updates, passing in the `toObjects`
The `applySectionDataBlock` block should be called prior to making any `UICollectionView` updates, passing in the `toObjects`
that the updater is applying.
*/
- (void)performExperimentalUpdateAnimated:(BOOL)animated
collectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock
dataBlock:(IGListTransitionDataBlock)dataBlock
applyDataBlock:(IGListTransitionDataApplyBlock)applyDataBlock
completion:(nullable IGListUpdatingCompletion)completion;
- (void)performUpdateWithCollectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock
animated:(BOOL)animated
sectionDataBlock:(IGListTransitionDataBlock)sectionDataBlock
applySectionDataBlock:(IGListTransitionDataApplyBlock)applySectionDataBlock
completion:(nullable IGListUpdatingCompletion)completion;
/**
Perform an **item** update block in the collection view.

View file

@ -26,8 +26,8 @@ IGLK_SUBCLASSING_RESTRICTED
delegate:(nullable id<IGListAdapterUpdaterDelegate>)delegate
config:(IGListUpdateTransactationConfig)config
animated:(BOOL)animated
dataBlock:(nullable IGListTransitionDataBlock)dataBlock
applyDataBlock:(nullable IGListTransitionDataApplyBlock)applyDataBlock
sectionDataBlock:(nullable IGListTransitionDataBlock)sectionDataBlock
applySectionDataBlock:(nullable IGListTransitionDataApplyBlock)applySectionDataBlock
itemUpdateBlocks:(NSArray<IGListItemUpdateBlock> *)itemUpdateBlocks
completionBlocks:(NSArray<IGListUpdatingCompletion> *)completionBlocks NS_DESIGNATED_INITIALIZER;

View file

@ -33,8 +33,8 @@ typedef NS_ENUM (NSInteger, IGListBatchUpdateTransactionMode) {
@property (nonatomic, weak, readonly, nullable) id<IGListAdapterUpdaterDelegate> delegate;
@property (nonatomic, assign, readonly) IGListUpdateTransactationConfig config;
@property (nonatomic, assign, readonly) BOOL animated;
@property (nonatomic, copy, readonly, nullable) IGListTransitionData *data;
@property (nonatomic, copy, readonly, nullable) IGListTransitionDataApplyBlock applyDataBlock;
@property (nonatomic, copy, readonly, nullable) IGListTransitionData *sectionData;
@property (nonatomic, copy, readonly, nullable) IGListTransitionDataApplyBlock applySectionDataBlock;
@property (nonatomic, copy, readonly) NSArray<IGListItemUpdateBlock> *itemUpdateBlocks;
@property (nonatomic, copy, readonly) NSArray<IGListUpdatingCompletion> *completionBlocks;
// Internal
@ -52,8 +52,8 @@ typedef NS_ENUM (NSInteger, IGListBatchUpdateTransactionMode) {
delegate:(id<IGListAdapterUpdaterDelegate>)delegate
config:(IGListUpdateTransactationConfig)config
animated:(BOOL)animated
dataBlock:(IGListTransitionDataBlock)dataBlock
applyDataBlock:(IGListTransitionDataApplyBlock)applyDataBlock
sectionDataBlock:(IGListTransitionDataBlock)sectionDataBlock
applySectionDataBlock:(IGListTransitionDataApplyBlock)applySectionDataBlock
itemUpdateBlocks:(NSArray<IGListItemUpdateBlock> *)itemUpdateBlocks
completionBlocks:(NSArray<IGListUpdatingCompletion> *)completionBlocks {
if (self = [super init]) {
@ -62,8 +62,8 @@ typedef NS_ENUM (NSInteger, IGListBatchUpdateTransactionMode) {
_delegate = delegate;
_config = config;
_animated = animated;
_data = dataBlock ? dataBlock() : nil;
_applyDataBlock = [applyDataBlock copy];
_sectionData = sectionDataBlock ? sectionDataBlock() : nil;
_applySectionDataBlock = [applySectionDataBlock copy];
_itemUpdateBlocks = [itemUpdateBlocks copy];
_completionBlocks = [completionBlocks copy];
@ -84,7 +84,7 @@ typedef NS_ENUM (NSInteger, IGListBatchUpdateTransactionMode) {
}
#ifdef DEBUG
for (id obj in self.data.toObjects) {
for (id obj in self.sectionData.toObjects) {
IGAssert([obj conformsToProtocol:@protocol(IGListDiffable)],
@"In order to use IGListAdapterUpdater, object %@ must conform to IGListDiffable", obj);
IGAssert([obj diffIdentifier] != nil,
@ -106,7 +106,7 @@ typedef NS_ENUM (NSInteger, IGListBatchUpdateTransactionMode) {
}
- (void)_diff {
IGListTransitionData *data = self.data;
IGListTransitionData *data = self.sectionData;
[self.delegate listAdapterUpdater:self.updater willDiffFromObjects:data.fromObjects toObjects:data.toObjects];
const BOOL onBackground = IGListExperimentEnabled(self.config.experiments, IGListExperimentBackgroundDiffing);
@ -141,11 +141,11 @@ typedef NS_ENUM (NSInteger, IGListBatchUpdateTransactionMode) {
[self _bail];
} else if (diffResult.changeCount > 100 && self.config.allowsReloadingOnTooManyUpdates) {
[self _reload];
} else if (self.data && [self.collectionView numberOfSections] != self.data.fromObjects.count) {
} else if (self.sectionData && [self.collectionView numberOfSections] != self.sectionData.fromObjects.count) {
// If data is nil, there are no section updates.
IGFailAssert(@"The UICollectionView's section count (%i) didn't match the IGListAdapter's count (%i), so we can't performBatchUpdates. Falling back to reloadData.",
[self.collectionView numberOfSections],
self.data.fromObjects.count);
self.sectionData.fromObjects.count);
[self _reload];
} else {
[self _applyDiff:diffResult];
@ -154,8 +154,8 @@ typedef NS_ENUM (NSInteger, IGListBatchUpdateTransactionMode) {
[self.delegate listAdapterUpdater:self.updater
collectionView:self.collectionView
willCrashWithException:exception
fromObjects:self.data.fromObjects
toObjects:self.data.toObjects
fromObjects:self.sectionData.fromObjects
toObjects:self.sectionData.toObjects
diffResult:diffResult
updates:(id)_actualCollectionViewUpdates];
@throw exception;
@ -165,8 +165,8 @@ typedef NS_ENUM (NSInteger, IGListBatchUpdateTransactionMode) {
- (void)_applyDiff:(IGListIndexSetResult *)diffResult {
[self.delegate listAdapterUpdater:self.updater
willPerformBatchUpdatesWithCollectionView:self.collectionView
fromObjects:self.data.fromObjects
toObjects:self.data.toObjects
fromObjects:self.sectionData.fromObjects
toObjects:self.sectionData.toObjects
listIndexSetResult:diffResult
animated:self.animated];
@ -222,8 +222,8 @@ willPerformBatchUpdatesWithCollectionView:self.collectionView
// run the update block so that the adapter can set its items. this makes sure that just before the update is
// committed that the data source is updated to the /latest/ "toObjects". this makes the data source in sync
// with the items that the updater is transitioning to
if (self.applyDataBlock != nil && self.data != nil) {
self.applyDataBlock((IGListTransitionData *)self.data);
if (self.applySectionDataBlock != nil && self.sectionData != nil) {
self.applySectionDataBlock((IGListTransitionData *)self.sectionData);
}
// execute each item update block which should make calls like insert, delete, and reload for index paths
@ -261,7 +261,7 @@ willPerformBatchUpdatesWithCollectionView:self.collectionView
self.inUpdateItemCollector.itemDeletes,
self.inUpdateItemCollector.itemReloads,
self.inUpdateItemCollector.itemMoves,
self.data.fromObjects ?: @[],
self.sectionData.fromObjects ?: @[],
self.config.sectionMovesAsDeletesInserts,
self.config.preferItemReloadsForSectionReloads);
}

View file

@ -26,14 +26,14 @@ IGLK_SUBCLASSING_RESTRICTED
@param animated A flag indicating if the transition should be animated.
@param collectionViewBlock A block returning the collecion view to perform updates on.
@param dataBlock A block which returns the transition data
@param applyDataBlock A block that applies the data passed from the `dataBlock` block
@param sectionDataBlock A block which returns the transition data
@param applySectionDataBlock A block that applies the data passed from the `sectionDataBlock` block
@param completion A completion block to execute when the update is finished.
*/
- (void)addSectionBatchUpdateAnimated:(BOOL)animated
collectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock
dataBlock:(IGListTransitionDataBlock)dataBlock
applyDataBlock:(IGListTransitionDataApplyBlock)applyDataBlock
sectionDataBlock:(IGListTransitionDataBlock)sectionDataBlock
applySectionDataBlock:(IGListTransitionDataApplyBlock)applySectionDataBlock
completion:(nullable IGListUpdatingCompletion)completion;
/**

View file

@ -25,8 +25,8 @@ typedef NS_ENUM (NSInteger, IGListUpdateTransactionBuilderMode) {
@interface IGListUpdateTransactionBuilder ()
// Batch updates
@property (nonatomic, copy, readwrite, nullable) IGListTransitionDataBlock dataBlock;
@property (nonatomic, copy, readwrite, nullable) IGListTransitionDataApplyBlock applyDataBlock;
@property (nonatomic, copy, readwrite, nullable) IGListTransitionDataBlock sectionDataBlock;
@property (nonatomic, copy, readwrite, nullable) IGListTransitionDataApplyBlock applySectionDataBlock;
@property (nonatomic, strong, readonly) NSMutableArray<IGListItemUpdateBlock> *itemUpdateBlocks;
@property (nonatomic, assign, readwrite) BOOL animated;
// Reload
@ -54,8 +54,8 @@ typedef NS_ENUM (NSInteger, IGListUpdateTransactionBuilderMode) {
- (void)addSectionBatchUpdateAnimated:(BOOL)animated
collectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock
dataBlock:(IGListTransitionDataBlock)dataBlock
applyDataBlock:(IGListTransitionDataApplyBlock)applyDataBlock
sectionDataBlock:(IGListTransitionDataBlock)sectionDataBlock
applySectionDataBlock:(IGListTransitionDataApplyBlock)applySectionDataBlock
completion:(IGListUpdatingCompletion)completion {
self.mode = MAX(self.mode, IGListUpdateTransactionBuilderModeBatchUpdate);
@ -64,11 +64,11 @@ typedef NS_ENUM (NSInteger, IGListUpdateTransactionBuilderMode) {
self.animated = self.animated && animated;
self.collectionViewBlock = collectionViewBlock;
// will call the dataBlock after the dispatch
self.dataBlock = dataBlock;
// will call the sectionDataBlock after the dispatch
self.sectionDataBlock = sectionDataBlock;
// always use the last update block, even though this should always do the exact same thing
self.applyDataBlock = applyDataBlock;
self.applySectionDataBlock = applySectionDataBlock;
IGListUpdatingCompletion localCompletion = completion;
if (localCompletion) {
@ -124,8 +124,8 @@ typedef NS_ENUM (NSInteger, IGListUpdateTransactionBuilderMode) {
// Section update
self.animated = self.animated && builder.animated;
self.dataBlock = self.dataBlock ?: builder.dataBlock;
self.applyDataBlock = self.applyDataBlock ?: builder.applyDataBlock;
self.sectionDataBlock = self.sectionDataBlock ?: builder.sectionDataBlock;
self.applySectionDataBlock = self.applySectionDataBlock ?: builder.applySectionDataBlock;
// Item updates
[self.itemUpdateBlocks addObjectsFromArray:builder.itemUpdateBlocks];
@ -153,8 +153,8 @@ typedef NS_ENUM (NSInteger, IGListUpdateTransactionBuilderMode) {
delegate:delegate
config:config
animated:self.animated
dataBlock:self.dataBlock
applyDataBlock:self.applyDataBlock
sectionDataBlock:self.sectionDataBlock
applySectionDataBlock:self.applySectionDataBlock
itemUpdateBlocks:self.itemUpdateBlocks
completionBlocks:self.completionBlocks];
}
@ -186,7 +186,7 @@ typedef NS_ENUM (NSInteger, IGListUpdateTransactionBuilderMode) {
return self.mode == IGListUpdateTransactionBuilderModeReload
|| self.mode == IGListUpdateTransactionBuilderModeDataSourceChange
|| self.itemUpdateBlocks.count > 0
|| self.dataBlock != nil;
|| self.sectionDataBlock != nil;
}
@end

View file

@ -28,7 +28,7 @@
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) IGListTestUICollectionViewDataSource *dataSource;
@property (nonatomic, strong) IGListAdapterUpdater *updater;
@property (nonatomic, strong) IGListTransitionDataApplyBlock applyDataBlock;
@property (nonatomic, strong) IGListTransitionDataApplyBlock applySectionDataBlock;
@end
@ -57,7 +57,7 @@
self.dataSource = [[IGListTestUICollectionViewDataSource alloc] initWithCollectionView:self.collectionView];
self.updater = [IGListAdapterUpdater new];
__weak __typeof__(self) weakSelf = self;
self.applyDataBlock = ^(IGListTransitionData *data) {
self.applySectionDataBlock = ^(IGListTransitionData *data) {
weakSelf.dataSource.sections = data.toObjects;
};
}
@ -71,29 +71,29 @@
}
- (void)test_whenUpdatingtoObjects_thatUpdaterHasChanges {
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:@[] toObjects:@[@0]]
applyDataBlock:self.applyDataBlock
completion:nil];
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:@[] toObjects:@[@0]]
applySectionDataBlock:self.applySectionDataBlock
completion:nil];
XCTAssertTrue([self.updater hasChanges]);
}
- (void)test_whenUpdatingfromObjects_thatUpdaterHasChanges {
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:@[@0] toObjects:@[]]
applyDataBlock:self.applyDataBlock
completion:nil];
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:@[@0] toObjects:@[]]
applySectionDataBlock:self.applySectionDataBlock
completion:nil];
XCTAssertTrue([self.updater hasChanges]);
}
- (void)test_whenUpdatingtoObjects_withfromObjects_thatUpdaterHasChanges {
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:@[@0] toObjects:@[@1]]
applyDataBlock:self.applyDataBlock
completion:nil];
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:@[@0] toObjects:@[@1]]
applySectionDataBlock:self.applySectionDataBlock
completion:nil];
XCTAssertTrue([self.updater hasChanges]);
}
@ -136,11 +136,11 @@
XCTAssertEqual([self.collectionView numberOfSections], 1);
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
XCTAssertEqual([self.collectionView numberOfSections], 2);
[expectation fulfill];
}];
@ -162,11 +162,11 @@
XCTAssertEqual([self.collectionView numberOfSections], 2);
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
XCTAssertEqual([self.collectionView numberOfSections], 1);
[expectation fulfill];
}];
@ -189,11 +189,11 @@
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 1);
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
XCTAssertEqual([self.collectionView numberOfSections], 2);
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
XCTAssertEqual([self.collectionView numberOfItemsInSection:1], 2);
@ -221,11 +221,11 @@
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 3);
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
XCTAssertEqual([self.collectionView numberOfSections], 3);
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
XCTAssertEqual([self.collectionView numberOfItemsInSection:1], 1);
@ -237,9 +237,9 @@
- (void)test_whenReloadingSections_thatCollectionViewUpdates {
self.dataSource.sections = @[
[IGSectionObject sectionWithObjects:@[@0, @1]],
[IGSectionObject sectionWithObjects:@[@0, @1]]
];
[IGSectionObject sectionWithObjects:@[@0, @1]],
[IGSectionObject sectionWithObjects:@[@0, @1]]
];
[self.updater reloadDataWithCollectionViewBlock:[self collectionViewBlock] reloadUpdateBlock:^{} completion:nil];
[self.updater update];
XCTAssertEqual([self.collectionView numberOfSections], 2);
@ -247,9 +247,9 @@
XCTAssertEqual([self.collectionView numberOfItemsInSection:1], 2);
self.dataSource.sections = @[
[IGSectionObject sectionWithObjects:@[@0, @1, @2]],
[IGSectionObject sectionWithObjects:@[@0, @1]]
];
[IGSectionObject sectionWithObjects:@[@0, @1, @2]],
[IGSectionObject sectionWithObjects:@[@0, @1]]
];
[self.updater reloadCollectionView:self.collectionView sections:[NSIndexSet indexSetWithIndex:0]];
XCTAssertEqual([self.collectionView numberOfSections], 2);
@ -276,11 +276,11 @@
[self.collectionView setNeedsLayout];
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
XCTAssertEqual([self.collectionView numberOfSections], 1);
[expectation fulfill];
}];
@ -309,11 +309,11 @@
[IGSectionObject sectionWithObjects:@[]],
[IGSectionObject sectionWithObjects:@[]]
];
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:to toObjects:anotherTo]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:to toObjects:anotherTo]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
completionCounter++;
XCTAssertEqual([self.collectionView numberOfSections], 3);
XCTAssertEqual(completionCounter, 2);
@ -322,10 +322,10 @@
};
XCTestExpectation *expectation2 = genExpectation;
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:^(IGListTransitionData *data) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:^(IGListTransitionData *data) {
// executing this block within the updater is just before performBatchUpdates: are applied
// should be able to queue another update here, similar to an update being queued between it beginning and executing
// the performBatchUpdates: block
@ -333,7 +333,7 @@
self.dataSource.sections = data.toObjects;
}
completion:^(BOOL finished) {
completion:^(BOOL finished) {
completionCounter++;
XCTAssertEqual([self.collectionView numberOfSections], 2);
XCTAssertEqual(completionCounter, 1);
@ -360,14 +360,14 @@
__block BOOL itemUpdateBlockExecuted = NO;
__block BOOL sectionUpdateBlockExecuted = NO;
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:@[] toObjects:@[[IGSectionObject sectionWithObjects:@[@1]]]]
applyDataBlock:^(IGListTransitionData * data) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:@[] toObjects:@[[IGSectionObject sectionWithObjects:@[@1]]]]
applySectionDataBlock:^(IGListTransitionData * data) {
self.dataSource.sections = data.toObjects;
sectionUpdateBlockExecuted = YES;
}
completion:nil];
completion:nil];
XCTestExpectation *expectation = genExpectation;
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock] animated:YES itemUpdates:^{
@ -410,11 +410,11 @@
self.updater.sectionMovesAsDeletesInserts = YES;
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
XCTAssertEqual([self.collectionView numberOfSections], 3);
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 1);
XCTAssertEqual([self.collectionView numberOfItemsInSection:1], 2);
@ -500,9 +500,9 @@
// 2 sections, 1 item in 1st, 4 items in 2nd
dataSource.sections = @[
[IGSectionObject sectionWithObjects:@[@1]],
[IGSectionObject sectionWithObjects:@[@1, @2, @3, @4]]
];
[IGSectionObject sectionWithObjects:@[@1]],
[IGSectionObject sectionWithObjects:@[@1, @2, @3, @4]]
];
// assert the initial state of the collection view WITHOUT any layoutSubviews or anything
XCTAssertEqual([collectionView numberOfSections], 2);
@ -510,8 +510,8 @@
XCTAssertEqual([collectionView numberOfItemsInSection:1], 4);
dataSource.sections = @[
[IGSectionObject sectionWithObjects:@[@1]],
];
[IGSectionObject sectionWithObjects:@[@1]],
];
IGListAdapterUpdater *updater = [IGListAdapterUpdater new];
[updater reloadDataWithCollectionViewBlock:^UICollectionView *{ return collectionView; } reloadUpdateBlock:^{} completion:nil];
@ -521,9 +521,9 @@
XCTAssertEqual([collectionView numberOfItemsInSection:0], 1);
dataSource.sections = @[
[IGSectionObject sectionWithObjects:@[@1]],
[IGSectionObject sectionWithObjects:@[@1, @2, @3, @4]]
];
[IGSectionObject sectionWithObjects:@[@1]],
[IGSectionObject sectionWithObjects:@[@1, @2, @3, @4]]
];
[updater reloadDataWithCollectionViewBlock:^UICollectionView *{ return collectionView; } reloadUpdateBlock:^{} completion:nil];
[updater update];
@ -546,11 +546,11 @@
[[mockDelegate expect] listAdapterUpdater:self.updater didPerformBatchUpdates:OCMOCK_ANY collectionView:self.collectionView];
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:self.dataSource.sections toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:self.dataSource.sections toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;
@ -571,11 +571,11 @@
NSArray *to = @[
[IGSectionObject sectionWithObjects:@[]]
];
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:self.dataSource.sections toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:self.dataSource.sections toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;
@ -597,11 +597,11 @@
[IGSectionObject sectionWithObjects:@[]]
];
self.collectionView.dataSource = nil;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:self.dataSource.sections toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:self.dataSource.sections toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;
@ -622,12 +622,12 @@
animated:YES itemUpdates:^{
object.objects = @[@2, @1, @4, @5];
[self.updater insertItemsIntoCollectionView:self.collectionView indexPaths:@[
[NSIndexPath indexPathForItem:2 inSection:0],
[NSIndexPath indexPathForItem:3 inSection:0],
]];
[NSIndexPath indexPathForItem:2 inSection:0],
[NSIndexPath indexPathForItem:3 inSection:0],
]];
[self.updater deleteItemsFromCollectionView:self.collectionView indexPaths:@[
[NSIndexPath indexPathForItem:0 inSection:0],
]];
[NSIndexPath indexPathForItem:0 inSection:0],
]];
[self.updater moveItemInCollectionView:self.collectionView
fromIndexPath:[NSIndexPath indexPathForItem:2 inSection:0]
toIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
@ -678,13 +678,13 @@
}];
};
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:self.dataSource.sections toObjects:self.dataSource.sections]
applyDataBlock:^(IGListTransitionData * _Nonnull data) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:self.dataSource.sections toObjects:self.dataSource.sections]
applySectionDataBlock:^(IGListTransitionData * _Nonnull data) {
updateItemBlock();
}
completion:nil];
completion:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}
@ -697,13 +697,13 @@
__block BOOL objectTransitionBlockExecuted = NO;
__block BOOL completionBlockExecuted = NO;
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:self.dataSource.sections toObjects:self.dataSource.sections]
applyDataBlock:^(IGListTransitionData *data) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:self.dataSource.sections toObjects:self.dataSource.sections]
applySectionDataBlock:^(IGListTransitionData *data) {
objectTransitionBlockExecuted = YES;
}
completion:^(BOOL finished) {
completion:^(BOOL finished) {
completionBlockExecuted = YES;
}];
@ -711,12 +711,12 @@
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock] animated:YES itemUpdates:^{
object.objects = @[@2, @1, @4, @5];
[self.updater insertItemsIntoCollectionView:self.collectionView indexPaths:@[
[NSIndexPath indexPathForItem:2 inSection:0],
[NSIndexPath indexPathForItem:3 inSection:0],
]];
[NSIndexPath indexPathForItem:2 inSection:0],
[NSIndexPath indexPathForItem:3 inSection:0],
]];
[self.updater deleteItemsFromCollectionView:self.collectionView indexPaths:@[
[NSIndexPath indexPathForItem:0 inSection:0],
]];
[NSIndexPath indexPathForItem:0 inSection:0],
]];
[self.updater moveItemInCollectionView:self.collectionView
fromIndexPath:[NSIndexPath indexPathForItem:2 inSection:0]
toIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
@ -751,13 +751,13 @@
object.objects = @[@1, @2];
[self.updater deleteItemsFromCollectionView:self.collectionView indexPaths:@[
[NSIndexPath indexPathForItem:0 inSection:0],
]];
[NSIndexPath indexPathForItem:0 inSection:0],
]];
object.objects = @[@1, @2, @4, @5];
[self.updater insertItemsIntoCollectionView:self.collectionView indexPaths:@[
[NSIndexPath indexPathForItem:2 inSection:0],
[NSIndexPath indexPathForItem:3 inSection:0],
]];
[NSIndexPath indexPathForItem:2 inSection:0],
[NSIndexPath indexPathForItem:3 inSection:0],
]];
object.objects = @[@2, @1, @4, @5];
[self.updater moveItemInCollectionView:self.collectionView
fromIndexPath:[NSIndexPath indexPathForItem:2 inSection:0]
@ -808,11 +808,11 @@
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;
@ -834,10 +834,10 @@
// Manually set the data source to be nil.
self->_collectionView.dataSource = nil;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:^(IGListTransitionData *data) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:^(IGListTransitionData *data) {
}
completion:^(BOOL finished) {
[expectation fulfill];
@ -895,20 +895,20 @@
[self.updater update];
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:objects1 toObjects:objects2]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:objects1 toObjects:objects2]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
XCTAssertEqual([self.collectionView numberOfSections], 2);
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
XCTAssertEqual([self.collectionView numberOfItemsInSection:1], 2);
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:objects2 toObjects:objects3]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished2) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:objects2 toObjects:objects3]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished2) {
XCTAssertEqual([self.collectionView numberOfSections], 3);
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
XCTAssertEqual([self.collectionView numberOfItemsInSection:1], 2);
@ -947,11 +947,11 @@
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;
@ -973,11 +973,11 @@
XCTAssertEqual([self.collectionView numberOfSections], 1);
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:YES
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:YES
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
XCTAssertEqual([self.collectionView numberOfSections], 2);
[expectation fulfill];
}];
@ -1027,11 +1027,11 @@
[[mockDelegate expect] listAdapterUpdater:self.updater didFinishWithoutUpdatesWithCollectionView:self.collectionView];
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
XCTAssertTrue(finished);
XCTAssertEqual([self.collectionView numberOfSections], 1);
[expectation fulfill];
@ -1067,11 +1067,11 @@
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;
@ -1103,11 +1103,11 @@
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;
@ -1145,11 +1145,11 @@
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;
@ -1187,11 +1187,11 @@
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;
@ -1231,11 +1231,11 @@
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;
@ -1270,11 +1270,11 @@
XCTestExpectation *expectation = genExpectation;
[self.updater performExperimentalUpdateAnimated:NO
collectionViewBlock:[self collectionViewBlock]
dataBlock:[self dataBlockFromObjects:from toObjects:to]
applyDataBlock:self.applyDataBlock
completion:^(BOOL finished) {
[self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock]
animated:NO
sectionDataBlock:[self dataBlockFromObjects:from toObjects:to]
applySectionDataBlock:self.applySectionDataBlock
completion:^(BOOL finished) {
[expectation fulfill];
}];
waitExpectation;