Rename the field again to nodeModel (#504)

* Rename the field to nodeModel

* A few more instances

* Fix method name
This commit is contained in:
Adlai Holler
2017-08-10 16:11:12 -07:00
committed by GitHub
parent dc3be352af
commit f58b0b3cd3
12 changed files with 66 additions and 66 deletions

View File

@@ -13,7 +13,7 @@
- Add -[ASDisplayNode detailedLayoutDescription] property to aid debugging. [Adlai Holler](https://github.com/Adlai-Holler) [#476](https://github.com/TextureGroup/Texture/pull/476) - Add -[ASDisplayNode detailedLayoutDescription] property to aid debugging. [Adlai Holler](https://github.com/Adlai-Holler) [#476](https://github.com/TextureGroup/Texture/pull/476)
- Fix an issue that causes calculatedLayoutDidChange being called needlessly. [Huy Nguyen](https://github.com/nguyenhuy) [#490](https://github.com/TextureGroup/Texture/pull/490) - Fix an issue that causes calculatedLayoutDidChange being called needlessly. [Huy Nguyen](https://github.com/nguyenhuy) [#490](https://github.com/TextureGroup/Texture/pull/490)
- Negate iOS 11 automatic estimated table row heights. [Christian Selig](https://github.com/christianselig) [#485](https://github.com/TextureGroup/Texture/pull/485) - Negate iOS 11 automatic estimated table row heights. [Christian Selig](https://github.com/christianselig) [#485](https://github.com/TextureGroup/Texture/pull/485)
- Rename ASCellNode.viewModel to ASCellNode.nodeViewModel to reduce collisions with subclass properties implemented by clients. [Adlai Holler](https://github.com/Adlai-Holler) [#499](https://github.com/TextureGroup/Texture/pull/499) - Rename ASCellNode.viewModel to ASCellNode.nodeModel to reduce collisions with subclass properties implemented by clients. [Adlai Holler](https://github.com/Adlai-Holler) [#504](https://github.com/TextureGroup/Texture/pull/504)
- [Breaking] Add content offset bridging property to ASTableNode and ASCollectionNode. Deprecate related methods in ASTableView and ASCollectionView [Huy Nguyen](https://github.com/nguyenhuy) [#460](https://github.com/TextureGroup/Texture/pull/460) - [Breaking] Add content offset bridging property to ASTableNode and ASCollectionNode. Deprecate related methods in ASTableView and ASCollectionView [Huy Nguyen](https://github.com/nguyenhuy) [#460](https://github.com/TextureGroup/Texture/pull/460)
##2.3.5 ##2.3.5

View File

@@ -123,14 +123,14 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
* *
* This property may be set off the main thread, but this method will never be invoked concurrently on the * This property may be set off the main thread, but this method will never be invoked concurrently on the
*/ */
@property (atomic, nullable) id nodeViewModel; @property (atomic, nullable) id nodeModel;
/** /**
* Asks the node whether it can be updated to the given view model. * Asks the node whether it can be updated to the given node model.
* *
* The default implementation returns YES if the class matches that of the current view-model. * The default implementation returns YES if the class matches that of the current view-model.
*/ */
- (BOOL)canUpdateToViewModel:(id)viewModel; - (BOOL)canUpdateToNodeModel:(id)nodeModel;
/** /**
* The backing view controller, or @c nil if the node wasn't initialized with backing view controller * The backing view controller, or @c nil if the node wasn't initialized with backing view controller

View File

@@ -170,9 +170,9 @@
} }
} }
- (BOOL)canUpdateToViewModel:(id)viewModel - (BOOL)canUpdateToNodeModel:(id)nodeModel
{ {
return [self.nodeViewModel class] == [viewModel class]; return [self.nodeModel class] == [nodeModel class];
} }
- (NSIndexPath *)indexPath - (NSIndexPath *)indexPath

View File

@@ -433,15 +433,15 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable __kindof ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT; - (nullable __kindof ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
/** /**
* Retrieves the view-model for the item at the given index path, if any. * Retrieves the node-model for the item at the given index path, if any.
* *
* @param indexPath The index path of the requested item. * @param indexPath The index path of the requested item.
* *
* @return The view-model for the given item, or @c nil if no item exists at the specified path or no view-model was provided. * @return The node-model for the given item, or @c nil if no item exists at the specified path or no node-model was provided.
* *
* @warning This API is beta and subject to change. We'll try to provide an easy migration path. * @warning This API is beta and subject to change. We'll try to provide an easy migration path.
*/ */
- (nullable id)viewModelForItemAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT; - (nullable id)nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
/** /**
* Retrieve the index path for the item with the given node. * Retrieve the index path for the item with the given node.
@@ -537,7 +537,7 @@ NS_ASSUME_NONNULL_BEGIN
* *
* @return An object that contains all the data for this item. * @return An object that contains all the data for this item.
*/ */
- (nullable id)collectionNode:(ASCollectionNode *)collectionNode viewModelForItemAtIndexPath:(NSIndexPath *)indexPath; - (nullable id)collectionNode:(ASCollectionNode *)collectionNode nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath;
/** /**
* Similar to -collectionNode:nodeForItemAtIndexPath: * Similar to -collectionNode:nodeForItemAtIndexPath:

View File

@@ -624,10 +624,10 @@
return [self.dataController.pendingMap elementForItemAtIndexPath:indexPath].node; return [self.dataController.pendingMap elementForItemAtIndexPath:indexPath].node;
} }
- (id)viewModelForItemAtIndexPath:(NSIndexPath *)indexPath - (id)nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath
{ {
[self reloadDataInitiallyIfNeeded]; [self reloadDataInitiallyIfNeeded];
return [self.dataController.pendingMap elementForItemAtIndexPath:indexPath].viewModel; return [self.dataController.pendingMap elementForItemAtIndexPath:indexPath].nodeModel;
} }
- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode - (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode

View File

@@ -202,7 +202,7 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
unsigned int collectionViewNumberOfItemsInSection:1; unsigned int collectionViewNumberOfItemsInSection:1;
unsigned int collectionNodeNodeForItem:1; unsigned int collectionNodeNodeForItem:1;
unsigned int collectionNodeNodeBlockForItem:1; unsigned int collectionNodeNodeBlockForItem:1;
unsigned int viewModelForItem:1; unsigned int nodeModelForItem:1;
unsigned int collectionNodeNodeForSupplementaryElement:1; unsigned int collectionNodeNodeForSupplementaryElement:1;
unsigned int collectionNodeNodeBlockForSupplementaryElement:1; unsigned int collectionNodeNodeBlockForSupplementaryElement:1;
unsigned int collectionNodeSupplementaryElementKindsInSection:1; unsigned int collectionNodeSupplementaryElementKindsInSection:1;
@@ -431,7 +431,7 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
_asyncDataSourceFlags.collectionNodeNodeForSupplementaryElement = [_asyncDataSource respondsToSelector:@selector(collectionNode:nodeForSupplementaryElementOfKind:atIndexPath:)]; _asyncDataSourceFlags.collectionNodeNodeForSupplementaryElement = [_asyncDataSource respondsToSelector:@selector(collectionNode:nodeForSupplementaryElementOfKind:atIndexPath:)];
_asyncDataSourceFlags.collectionNodeNodeBlockForSupplementaryElement = [_asyncDataSource respondsToSelector:@selector(collectionNode:nodeBlockForSupplementaryElementOfKind:atIndexPath:)]; _asyncDataSourceFlags.collectionNodeNodeBlockForSupplementaryElement = [_asyncDataSource respondsToSelector:@selector(collectionNode:nodeBlockForSupplementaryElementOfKind:atIndexPath:)];
_asyncDataSourceFlags.collectionNodeSupplementaryElementKindsInSection = [_asyncDataSource respondsToSelector:@selector(collectionNode:supplementaryElementKindsInSection:)]; _asyncDataSourceFlags.collectionNodeSupplementaryElementKindsInSection = [_asyncDataSource respondsToSelector:@selector(collectionNode:supplementaryElementKindsInSection:)];
_asyncDataSourceFlags.viewModelForItem = [_asyncDataSource respondsToSelector:@selector(collectionNode:viewModelForItemAtIndexPath:)]; _asyncDataSourceFlags.nodeModelForItem = [_asyncDataSource respondsToSelector:@selector(collectionNode:nodeModelForItemAtIndexPath:)];
_asyncDataSourceFlags.interop = [_asyncDataSource conformsToProtocol:@protocol(ASCollectionDataSourceInterop)]; _asyncDataSourceFlags.interop = [_asyncDataSource conformsToProtocol:@protocol(ASCollectionDataSourceInterop)];
if (_asyncDataSourceFlags.interop) { if (_asyncDataSourceFlags.interop) {
@@ -1662,14 +1662,14 @@ minimumLineSpacingForSectionAtIndex:(NSInteger)section
#pragma mark - ASDataControllerSource #pragma mark - ASDataControllerSource
- (id)dataController:(ASDataController *)dataController viewModelForItemAtIndexPath:(NSIndexPath *)indexPath - (id)dataController:(ASDataController *)dataController nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath
{ {
if (!_asyncDataSourceFlags.viewModelForItem) { if (!_asyncDataSourceFlags.nodeModelForItem) {
return nil; return nil;
} }
GET_COLLECTIONNODE_OR_RETURN(collectionNode, nil); GET_COLLECTIONNODE_OR_RETURN(collectionNode, nil);
return [_asyncDataSource collectionNode:collectionNode viewModelForItemAtIndexPath:indexPath]; return [_asyncDataSource collectionNode:collectionNode nodeModelForItemAtIndexPath:indexPath];
} }
- (ASCellNodeBlock)dataController:(ASDataController *)dataController nodeBlockAtIndexPath:(NSIndexPath *)indexPath - (ASCellNodeBlock)dataController:(ASDataController *)dataController nodeBlockAtIndexPath:(NSIndexPath *)indexPath

View File

@@ -1628,7 +1628,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
#pragma mark - ASDataControllerSource #pragma mark - ASDataControllerSource
- (id)dataController:(ASDataController *)dataController viewModelForItemAtIndexPath:(NSIndexPath *)indexPath - (id)dataController:(ASDataController *)dataController nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath
{ {
// Not currently supported for tables. Will be added when the collection API stabilizes. // Not currently supported for tables. Will be added when the collection API stabilizes.
return nil; return nil;

View File

@@ -30,9 +30,9 @@ AS_SUBCLASSING_RESTRICTED
@property (nonatomic, assign) ASSizeRange constrainedSize; @property (nonatomic, assign) ASSizeRange constrainedSize;
@property (nonatomic, readonly, weak) id<ASRangeManagingNode> owningNode; @property (nonatomic, readonly, weak) id<ASRangeManagingNode> owningNode;
@property (nonatomic, assign) ASPrimitiveTraitCollection traitCollection; @property (nonatomic, assign) ASPrimitiveTraitCollection traitCollection;
@property (nonatomic, readonly, nullable) id viewModel; @property (nonatomic, readonly, nullable) id nodeModel;
- (instancetype)initWithViewModel:(nullable id)viewModel - (instancetype)initWithNodeModel:(nullable id)nodeModel
nodeBlock:(ASCellNodeBlock)nodeBlock nodeBlock:(ASCellNodeBlock)nodeBlock
supplementaryElementKind:(nullable NSString *)supplementaryElementKind supplementaryElementKind:(nullable NSString *)supplementaryElementKind
constrainedSize:(ASSizeRange)constrainedSize constrainedSize:(ASSizeRange)constrainedSize

View File

@@ -31,7 +31,7 @@
ASCellNode *_node; ASCellNode *_node;
} }
- (instancetype)initWithViewModel:(id)viewModel - (instancetype)initWithNodeModel:(id)nodeModel
nodeBlock:(ASCellNodeBlock)nodeBlock nodeBlock:(ASCellNodeBlock)nodeBlock
supplementaryElementKind:(NSString *)supplementaryElementKind supplementaryElementKind:(NSString *)supplementaryElementKind
constrainedSize:(ASSizeRange)constrainedSize constrainedSize:(ASSizeRange)constrainedSize
@@ -41,7 +41,7 @@
NSAssert(nodeBlock != nil, @"Node block must not be nil"); NSAssert(nodeBlock != nil, @"Node block must not be nil");
self = [super init]; self = [super init];
if (self) { if (self) {
_viewModel = viewModel; _nodeModel = nodeModel;
_nodeBlock = nodeBlock; _nodeBlock = nodeBlock;
_supplementaryElementKind = [supplementaryElementKind copy]; _supplementaryElementKind = [supplementaryElementKind copy];
_constrainedSize = constrainedSize; _constrainedSize = constrainedSize;
@@ -64,7 +64,7 @@
node.owningNode = _owningNode; node.owningNode = _owningNode;
node.collectionElement = self; node.collectionElement = self;
ASTraitCollectionPropagateDown(node, _traitCollection); ASTraitCollectionPropagateDown(node, _traitCollection);
node.nodeViewModel = _viewModel; node.nodeModel = _nodeModel;
_node = node; _node = node;
} }
return _node; return _node;

View File

@@ -78,7 +78,7 @@ extern NSString * const ASCollectionInvalidUpdateException;
*/ */
- (BOOL)dataController:(ASDataController *)dataController presentedSizeForElement:(ASCollectionElement *)element matchesSize:(CGSize)size; - (BOOL)dataController:(ASDataController *)dataController presentedSizeForElement:(ASCollectionElement *)element matchesSize:(CGSize)size;
- (nullable id)dataController:(ASDataController *)dataController viewModelForItemAtIndexPath:(NSIndexPath *)indexPath; - (nullable id)dataController:(ASDataController *)dataController nodeModelForItemAtIndexPath:(NSIndexPath *)indexPath;
@optional @optional

View File

@@ -330,18 +330,18 @@ typedef dispatch_block_t ASDataControllerCompletionBlock;
id<ASRangeManagingNode> node = self.node; id<ASRangeManagingNode> node = self.node;
for (NSIndexPath *indexPath in indexPaths) { for (NSIndexPath *indexPath in indexPaths) {
ASCellNodeBlock nodeBlock; ASCellNodeBlock nodeBlock;
id viewModel; id nodeModel;
if (isRowKind) { if (isRowKind) {
viewModel = [dataSource dataController:self viewModelForItemAtIndexPath:indexPath]; nodeModel = [dataSource dataController:self nodeModelForItemAtIndexPath:indexPath];
// Get the prior element and attempt to update the existing cell node. // Get the prior element and attempt to update the existing cell node.
if (viewModel != nil && !changeSet.includesReloadData) { if (nodeModel != nil && !changeSet.includesReloadData) {
NSIndexPath *oldIndexPath = [changeSet oldIndexPathForNewIndexPath:indexPath]; NSIndexPath *oldIndexPath = [changeSet oldIndexPathForNewIndexPath:indexPath];
if (oldIndexPath != nil) { if (oldIndexPath != nil) {
ASCollectionElement *oldElement = [previousMap elementForItemAtIndexPath:oldIndexPath]; ASCollectionElement *oldElement = [previousMap elementForItemAtIndexPath:oldIndexPath];
ASCellNode *oldNode = oldElement.node; ASCellNode *oldNode = oldElement.node;
if ([oldNode canUpdateToViewModel:viewModel]) { if ([oldNode canUpdateToNodeModel:nodeModel]) {
// Just wrap the node in a block. The collection element will -setViewModel: // Just wrap the node in a block. The collection element will -setNodeModel:
nodeBlock = ^{ nodeBlock = ^{
return oldNode; return oldNode;
}; };
@@ -360,7 +360,7 @@ typedef dispatch_block_t ASDataControllerCompletionBlock;
constrainedSize = [self constrainedSizeForNodeOfKind:kind atIndexPath:indexPath]; constrainedSize = [self constrainedSizeForNodeOfKind:kind atIndexPath:indexPath];
} }
ASCollectionElement *element = [[ASCollectionElement alloc] initWithViewModel:viewModel ASCollectionElement *element = [[ASCollectionElement alloc] initWithNodeModel:nodeModel
nodeBlock:nodeBlock nodeBlock:nodeBlock
supplementaryElementKind:isRowKind ? nil : kind supplementaryElementKind:isRowKind ? nil : kind
constrainedSize:constrainedSize constrainedSize:constrainedSize

View File

@@ -24,7 +24,7 @@
@end @end
@interface ASTestSection : NSObject <ASSectionContext> @interface ASTestSection : NSObject <ASSectionContext>
@property (nonatomic, readonly) NSMutableArray *viewModels; @property (nonatomic, readonly) NSMutableArray *nodeModels;
@end @end
@implementation ASCollectionModernDataSourceTests { @implementation ASCollectionModernDataSourceTests {
@@ -41,10 +41,10 @@
// Default is 2 sections: 2 items in first, 1 item in second. // Default is 2 sections: 2 items in first, 1 item in second.
sections = [NSMutableArray array]; sections = [NSMutableArray array];
[sections addObject:[ASTestSection new]]; [sections addObject:[ASTestSection new]];
[sections[0].viewModels addObject:[NSObject new]]; [sections[0].nodeModels addObject:[NSObject new]];
[sections[0].viewModels addObject:[NSObject new]]; [sections[0].nodeModels addObject:[NSObject new]];
[sections addObject:[ASTestSection new]]; [sections addObject:[ASTestSection new]];
[sections[1].viewModels addObject:[NSObject new]]; [sections[1].nodeModels addObject:[NSObject new]];
window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
viewController = [[UIViewController alloc] init]; viewController = [[UIViewController alloc] init];
@@ -60,7 +60,7 @@
@selector(numberOfSectionsInCollectionNode:), @selector(numberOfSectionsInCollectionNode:),
@selector(collectionNode:numberOfItemsInSection:), @selector(collectionNode:numberOfItemsInSection:),
@selector(collectionNode:nodeBlockForItemAtIndexPath:), @selector(collectionNode:nodeBlockForItemAtIndexPath:),
@selector(collectionNode:viewModelForItemAtIndexPath:), @selector(collectionNode:nodeModelForItemAtIndexPath:),
@selector(collectionNode:contextForSection:), @selector(collectionNode:contextForSection:),
nil]; nil];
[mockDataSource setExpectationOrderMatters:YES]; [mockDataSource setExpectationOrderMatters:YES];
@@ -112,7 +112,7 @@
skippedReloadIndexPaths:nil]; skippedReloadIndexPaths:nil];
} }
- (void)testReloadingAnItemWithACompatibleViewModel - (void)testReloadingAnItemWithACompatibleNodeModel
{ {
[self loadInitialData]; [self loadInitialData];
@@ -120,15 +120,15 @@
NSIndexPath *reloadedPath = [NSIndexPath indexPathForItem:1 inSection:0]; NSIndexPath *reloadedPath = [NSIndexPath indexPathForItem:1 inSection:0];
NSIndexPath *deletedPath = [NSIndexPath indexPathForItem:0 inSection:0]; NSIndexPath *deletedPath = [NSIndexPath indexPathForItem:0 inSection:0];
id viewModel = [NSObject new]; id nodeModel = [NSObject new];
// Cell node should get -canUpdateToViewModel: // Cell node should get -canUpdateToNodeModel:
id mockCellNode = [collectionNode nodeForItemAtIndexPath:reloadedPath]; id mockCellNode = [collectionNode nodeForItemAtIndexPath:reloadedPath];
OCMExpect([mockCellNode canUpdateToViewModel:viewModel]) OCMExpect([mockCellNode canUpdateToNodeModel:nodeModel])
.andReturn(YES); .andReturn(YES);
[self performUpdateReloadingSections:nil [self performUpdateReloadingSections:nil
reloadingItems:@{ reloadedPath: viewModel } reloadingItems:@{ reloadedPath: nodeModel }
reloadMappings:@{ reloadedPath: [NSIndexPath indexPathForItem:0 inSection:0] } reloadMappings:@{ reloadedPath: [NSIndexPath indexPathForItem:0 inSection:0] }
insertingItems:nil insertingItems:nil
deletingItems:@[ deletedPath ] deletingItems:@[ deletedPath ]
@@ -168,12 +168,12 @@
// It reads the contents for each item. // It reads the contents for each item.
for (NSInteger section = 0; section < sections.count; section++) { for (NSInteger section = 0; section < sections.count; section++) {
NSArray *viewModels = sections[section].viewModels; NSArray *nodeModels = sections[section].nodeModels;
// For each item: // For each item:
for (NSInteger i = 0; i < viewModels.count; i++) { for (NSInteger i = 0; i < nodeModels.count; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:section]; NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:section];
[self expectViewModelMethodForItemAtIndexPath:indexPath viewModel:viewModels[i]]; [self expectNodeModelMethodForItemAtIndexPath:indexPath nodeModel:nodeModels[i]];
[self expectNodeBlockMethodForItemAtIndexPath:indexPath]; [self expectNodeBlockMethodForItemAtIndexPath:indexPath];
} }
} }
@@ -201,14 +201,14 @@
// Note: Skip fast enumeration for readability. // Note: Skip fast enumeration for readability.
for (NSInteger section = 0; section < sections.count; section++) { for (NSInteger section = 0; section < sections.count; section++) {
OCMExpect([mockDataSource collectionNode:collectionNode numberOfItemsInSection:section]) OCMExpect([mockDataSource collectionNode:collectionNode numberOfItemsInSection:section])
.andReturn(sections[section].viewModels.count); .andReturn(sections[section].nodeModels.count);
} }
} }
- (void)expectViewModelMethodForItemAtIndexPath:(NSIndexPath *)indexPath viewModel:(id)viewModel - (void)expectNodeModelMethodForItemAtIndexPath:(NSIndexPath *)indexPath nodeModel:(id)nodeModel
{ {
OCMExpect([mockDataSource collectionNode:collectionNode viewModelForItemAtIndexPath:indexPath]) OCMExpect([mockDataSource collectionNode:collectionNode nodeModelForItemAtIndexPath:indexPath])
.andReturn(viewModel); .andReturn(nodeModel);
} }
- (void)expectContextMethodForSection:(NSInteger)section - (void)expectContextMethodForSection:(NSInteger)section
@@ -240,21 +240,21 @@
for (NSInteger section = 0; section < sections.count; section++) { for (NSInteger section = 0; section < sections.count; section++) {
ASTestSection *sectionObject = sections[section]; ASTestSection *sectionObject = sections[section];
NSArray *viewModels = sectionObject.viewModels; NSArray *nodeModels = sectionObject.nodeModels;
// Assert section object // Assert section object
XCTAssertEqualObjects([collectionNode contextForSection:section], sectionObject); XCTAssertEqualObjects([collectionNode contextForSection:section], sectionObject);
// Assert item count // Assert item count
XCTAssertEqual([collectionNode numberOfItemsInSection:section], viewModels.count); XCTAssertEqual([collectionNode numberOfItemsInSection:section], nodeModels.count);
for (NSInteger item = 0; item < viewModels.count; item++) { for (NSInteger item = 0; item < nodeModels.count; item++) {
// Assert view model // Assert node model
// Could use pointer equality but the error message is less readable. // Could use pointer equality but the error message is less readable.
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:section]; NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:section];
id viewModel = viewModels[indexPath.item]; id nodeModel = nodeModels[indexPath.item];
XCTAssertEqualObjects(viewModel, [collectionNode viewModelForItemAtIndexPath:indexPath]); XCTAssertEqualObjects(nodeModel, [collectionNode nodeModelForItemAtIndexPath:indexPath]);
ASCellNode *node = [collectionNode nodeForItemAtIndexPath:indexPath]; ASCellNode *node = [collectionNode nodeForItemAtIndexPath:indexPath];
XCTAssertEqualObjects(node.nodeViewModel, viewModel); XCTAssertEqualObjects(node.nodeModel, nodeModel);
} }
} }
} }
@@ -263,7 +263,7 @@
* Updates the collection node, with expectations and assertions about the call-order and the correctness of the * Updates the collection node, with expectations and assertions about the call-order and the correctness of the
* new data. You should update the data source _before_ calling this method. * new data. You should update the data source _before_ calling this method.
* *
* skippedReloadIndexPaths are the old index paths for nodes that should use -canUpdateToViewModel: instead of being refetched. * skippedReloadIndexPaths are the old index paths for nodes that should use -canUpdateToNodeModel: instead of being refetched.
*/ */
- (void)performUpdateReloadingSections:(NSDictionary<NSNumber *, id> *)reloadedSections - (void)performUpdateReloadingSections:(NSDictionary<NSNumber *, id> *)reloadedSections
reloadingItems:(NSDictionary<NSIndexPath *, id> *)reloadedItems reloadingItems:(NSDictionary<NSIndexPath *, id> *)reloadedItems
@@ -275,7 +275,7 @@
[collectionNode performBatchUpdates:^{ [collectionNode performBatchUpdates:^{
// First update our data source. // First update our data source.
[reloadedItems enumerateKeysAndObjectsUsingBlock:^(NSIndexPath * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { [reloadedItems enumerateKeysAndObjectsUsingBlock:^(NSIndexPath * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
sections[key.section].viewModels[key.item] = obj; sections[key.section].nodeModels[key.item] = obj;
}]; }];
[reloadedSections enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { [reloadedSections enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
sections[key.integerValue] = obj; sections[key.integerValue] = obj;
@@ -283,13 +283,13 @@
// Deletion paths, sorted descending // Deletion paths, sorted descending
for (NSIndexPath *indexPath in [deletedItems sortedArrayUsingSelector:@selector(compare:)].reverseObjectEnumerator) { for (NSIndexPath *indexPath in [deletedItems sortedArrayUsingSelector:@selector(compare:)].reverseObjectEnumerator) {
[sections[indexPath.section].viewModels removeObjectAtIndex:indexPath.item]; [sections[indexPath.section].nodeModels removeObjectAtIndex:indexPath.item];
} }
// Insertion paths, sorted ascending. // Insertion paths, sorted ascending.
NSArray *insertionsSortedAcending = [insertedItems.allKeys sortedArrayUsingSelector:@selector(compare:)]; NSArray *insertionsSortedAcending = [insertedItems.allKeys sortedArrayUsingSelector:@selector(compare:)];
for (NSIndexPath *indexPath in insertionsSortedAcending) { for (NSIndexPath *indexPath in insertionsSortedAcending) {
[sections[indexPath.section].viewModels insertObject:insertedItems[indexPath] atIndex:indexPath.item]; [sections[indexPath.section].nodeModels insertObject:insertedItems[indexPath] atIndex:indexPath.item];
} }
// Then update the collection node. // Then update the collection node.
@@ -314,10 +314,10 @@
// Go through reloaded sections and add all their items into `insertsPlusReloads` // Go through reloaded sections and add all their items into `insertsPlusReloads`
[reloadedSectionIndexes enumerateIndexesUsingBlock:^(NSUInteger section, BOOL * _Nonnull stop) { [reloadedSectionIndexes enumerateIndexesUsingBlock:^(NSUInteger section, BOOL * _Nonnull stop) {
[self expectContextMethodForSection:section]; [self expectContextMethodForSection:section];
NSArray *viewModels = sections[section].viewModels; NSArray *nodeModels = sections[section].nodeModels;
for (NSInteger i = 0; i < viewModels.count; i++) { for (NSInteger i = 0; i < nodeModels.count; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:section]; NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:section];
insertsPlusReloads[indexPath] = viewModels[i]; insertsPlusReloads[indexPath] = nodeModels[i];
} }
}]; }];
@@ -326,7 +326,7 @@
}]; }];
for (NSIndexPath *indexPath in [insertsPlusReloads.allKeys sortedArrayUsingSelector:@selector(compare:)]) { for (NSIndexPath *indexPath in [insertsPlusReloads.allKeys sortedArrayUsingSelector:@selector(compare:)]) {
[self expectViewModelMethodForItemAtIndexPath:indexPath viewModel:insertsPlusReloads[indexPath]]; [self expectNodeModelMethodForItemAtIndexPath:indexPath nodeModel:insertsPlusReloads[indexPath]];
NSIndexPath *oldIndexPath = [reloadMappings allKeysForObject:indexPath].firstObject; NSIndexPath *oldIndexPath = [reloadMappings allKeysForObject:indexPath].firstObject;
BOOL isSkippedReload = oldIndexPath && [skippedReloadIndexPaths containsObject:oldIndexPath]; BOOL isSkippedReload = oldIndexPath && [skippedReloadIndexPaths containsObject:oldIndexPath];
if (!isSkippedReload) { if (!isSkippedReload) {
@@ -335,7 +335,7 @@
} }
} completion:nil]; } completion:nil];
// Assert that the counts and view models are all correct now. // Assert that the counts and node models are all correct now.
[self assertCollectionNodeContent]; [self assertCollectionNodeContent];
} }
@@ -345,9 +345,9 @@
@implementation ASTestCellNode @implementation ASTestCellNode
- (BOOL)canUpdateToViewModel:(id)viewModel - (BOOL)canUpdateToNodeModel:(id)nodeModel
{ {
// Our tests default to NO for migrating view models. We use OCMExpect to return YES when we specifically want to. // Our tests default to NO for migrating node models. We use OCMExpect to return YES when we specifically want to.
return NO; return NO;
} }
@@ -360,7 +360,7 @@
- (instancetype)init - (instancetype)init
{ {
if (self = [super init]) { if (self = [super init]) {
_viewModels = [NSMutableArray array]; _nodeModels = [NSMutableArray array];
} }
return self; return self;
} }