ASCollectionNode API Update 2017-1
The current ASCollectionNode data source API very closely parallels UIKit’s, and it suffers from the same problems. We can do much better. The objectives are:

  • Use node controllers to represent collection items, and have them survive across updates.
  • Provide node controllers with API to handle common events (e.g. selection).
  • Provide node controllers with API to talk to higher controllers (e.g. section controllers, view controllers).
  • Provide support for updating cell node contents instead of reloading cells.
  • Make it easier to safely pipe model data to node controllers.

Public API: Object-NodeController Data Source API

Add optional methods to ASCollectionDataSource :

/**
 * Called synchronously on main thread when items are inserted. User returns arbitraryobject representing the current version of the item data.
 *
 * @param collectionNode The sender.
 * @param indexPath The index path of the object to retrieve.
 * @return The object that represents this item.
 */
- (id)collectionNode:(ASCollectionNode *)collectionNode objectAtIndexPath:(NSIndexPath *)indexPath;

/**
 * Called asynchronously after objects are gathered. User creates and returns an appropriate node controller for the given object.
 */
- (ASNodeController *)collectionNode:(ASCollectionNode *)node nodeControllerForObject:(id)object;

Note: We will continue to support collectionNode:nodeBlockForItemAtIndexPath: 

Internal Changes to Support New Data Source API
  • Update ASCollectionElement instead to have initWithObject:  and initWithNodeBlock: which would be selected based on the data source API that the user used.
  • Add a step in ASDataController on the editing queue to:
  • For inserted items: Request node controllers, assign them objects, assign node controller to element.
  • For updated items: Attempt to update the node controllers, request new node controllers for any that cannot be updated, assign node controller to element.
  • Note: Need to support hosting a new node in an existing cell. 

Public API: Node Controller Cell Updating Methods


Add to ASNodeController :

@interface ASNodeController (CollectionViewItemMethods)

/**
 * The index path of the item, if any, that this node controller is at in its collection.
 */
@property (copy, nullable, readonly) NSIndexPath *indexPath;

/**
 * The object currently assigned to this node controller, if any.
 */
@property (strong, nullable, readonly) id object;