Merge pull request #303 from facebook/enable_async_data_fetching

Move ASTableView & ASCollectionView data fetching to background thread
This commit is contained in:
Nadine Salter
2015-02-23 15:25:36 -08:00
8 changed files with 334 additions and 126 deletions

View File

@@ -28,13 +28,23 @@ typedef NSUInteger ASDataControllerAnimationOptions;
/**
Fetch the number of rows in specific section.
*/
- (NSUInteger)dataController:(ASDataController *)dataControllre rowsInSection:(NSUInteger)section;
- (NSUInteger)dataController:(ASDataController *)dataController rowsInSection:(NSUInteger)section;
/**
Fetch the number of sections.
*/
- (NSUInteger)dataControllerNumberOfSections:(ASDataController *)dataController;
/**
Lock the data source for data fetching.
*/
- (void)dataControllerLockDataSource;
/**
Unlock the data source after data fetching.
*/
- (void)dataControllerUnlockDataSource;
@end
/**
@@ -97,6 +107,20 @@ typedef NSUInteger ASDataControllerAnimationOptions;
*/
@property (nonatomic, weak) id<ASDataControllerDelegate> delegate;
/**
* Designated iniailizer.
*
* @param asyncDataFetchingEnabled Enable the data fetching in async mode.
* @discussion If enabled, we will fetch data through `dataController:nodeAtIndexPath:` and `dataController:rowsInSection:` in background thread.
* Otherwise, the methods will be invoked synchronically in calling thread. Enabling data fetching in async mode could avoid blocking main thread
* while allocating cell on main thread, which is frequently reported issue for handing large scale data. On another hand, the application code
* will take the responsibility to avoid data inconsistence. Specifically, we will lock the data source through `dataControllerLockDataSource`,
* and unlock it by `dataControllerUnlockDataSource` after the data fetching. The application should not update the data source while
* the data source is locked.
*/
- (instancetype)initWithAsyncDataFetching:(BOOL)asyncDataFetchingEnabled;
/** @name Initial loading */
- (void)initialDataLoadingWithAnimationOption:(ASDataControllerAnimationOptions)animationOption;