@@ -43,7 +43,6 @@ @interface ASDataController () {
4343 BOOL _delegateDidDeleteNodes;
4444 BOOL _delegateDidInsertSections;
4545 BOOL _delegateDidDeleteSections;
46- BOOL _delegateDidReloadData;
4746}
4847
4948@property (atomic , assign ) NSUInteger batchUpdateCounter;
@@ -93,7 +92,6 @@ - (void)setDelegate:(id<ASDataControllerDelegate>)delegate
9392 _delegateDidDeleteNodes = [_delegate respondsToSelector: @selector (dataController:didDeleteNodes:atIndexPaths:withAnimationOptions: )];
9493 _delegateDidInsertSections = [_delegate respondsToSelector: @selector (dataController:didInsertSections:atIndexSet:withAnimationOptions: )];
9594 _delegateDidDeleteSections = [_delegate respondsToSelector: @selector (dataController:didDeleteSectionsAtIndexSet:withAnimationOptions: )];
96- _delegateDidReloadData = [_delegate respondsToSelector: @selector (dataControllerDidReloadData: )];
9795}
9896
9997+ (NSUInteger )parallelProcessorCount
@@ -145,30 +143,14 @@ - (void)_layoutNode:(ASCellNode *)node withConstrainedSize:(ASSizeRange)constrai
145143 node.frame = CGRectMake (0 .0f , 0 .0f , node.calculatedSize .width , node.calculatedSize .height );
146144}
147145
148- /* *
149- * Measures and defines the layout for each node in optimized batches on an editing queue, inserting the results into the backing store.
150- */
151- - (void )_batchLayoutNodes : (NSArray *)nodes atIndexPaths : (NSArray *)indexPaths
152- {
153- [self _batchLayoutNodes: nodes atIndexPaths: indexPaths andNotifyDelegate: NO withAnimationOptions: 0 ];
154- }
155-
156146/* *
157147 * Measures and defines the layout for each node in optimized batches on an editing queue, inserting the results into the backing store.
158148 */
159149- (void )_batchLayoutNodes : (NSArray *)nodes atIndexPaths : (NSArray *)indexPaths withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
160- {
161- [self _batchLayoutNodes: nodes atIndexPaths: indexPaths andNotifyDelegate: YES withAnimationOptions: animationOptions];
162- }
163-
164- /* *
165- * Measures and defines the layout for each node in optimized batches on an editing queue, inserting the results into the backing store.
166- */
167- - (void )_batchLayoutNodes : (NSArray *)nodes atIndexPaths : (NSArray *)indexPaths andNotifyDelegate : (BOOL )shouldNotifyDelegate withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
168150{
169151 [self batchLayoutNodes: nodes ofKind: ASDataControllerRowNodeKind atIndexPaths: indexPaths completion: ^(NSArray *nodes, NSArray *indexPaths) {
170152 // Insert finished nodes into data storage
171- [self _insertNodes: nodes atIndexPaths: indexPaths andNotifyDelegate: shouldNotifyDelegate withAnimationOptions: animationOptions];
153+ [self _insertNodes: nodes atIndexPaths: indexPaths withAnimationOptions: animationOptions];
172154 }];
173155}
174156
@@ -258,14 +240,6 @@ - (void)deleteNodesOfKind:(NSString *)kind atIndexPaths:(NSArray *)indexPaths co
258240 }];
259241}
260242
261- - (void )deleteAllNodesOfKind : (NSString *)kind
262- {
263- [_editingNodes[kind] removeAllObjects ];
264- [_mainSerialQueue performBlockOnMainThread: ^{
265- [_completedNodes[kind] removeAllObjects ];
266- }];
267- }
268-
269243- (void )insertSections : (NSMutableArray *)sections ofKind : (NSString *)kind atIndexSet : (NSIndexSet *)indexSet completion : (void (^)(NSArray *sections, NSIndexSet *indexSet))completionBlock
270244{
271245 if (indexSet.count == 0 )
@@ -303,17 +277,6 @@ - (void)deleteSectionsOfKind:(NSString *)kind atIndexSet:(NSIndexSet *)indexSet
303277
304278#pragma mark - Internal Data Querying + Editing
305279
306- /* *
307- * Inserts the specified nodes into the given index paths and doesn't notify the delegate of newly inserted nodes.
308- *
309- * @discussion Nodes are first inserted into the editing store, then the completed store is replaced by a deep copy
310- * of the editing nodes.
311- */
312- - (void )_insertNodes : (NSArray *)nodes atIndexPaths : (NSArray *)indexPaths
313- {
314- [self _insertNodes: nodes atIndexPaths: indexPaths andNotifyDelegate: NO withAnimationOptions: 0 ];
315- }
316-
317280/* *
318281 * Inserts the specified nodes into the given index paths and notifies the delegate of newly inserted nodes.
319282 *
@@ -322,26 +285,10 @@ - (void)_insertNodes:(NSArray *)nodes atIndexPaths:(NSArray *)indexPaths
322285 */
323286- (void )_insertNodes : (NSArray *)nodes atIndexPaths : (NSArray *)indexPaths withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
324287{
325- [self _insertNodes: nodes atIndexPaths: indexPaths andNotifyDelegate: YES withAnimationOptions: animationOptions];
326- }
327-
328- /* *
329- * Inserts the specified nodes into the given index paths and notifies the delegate of newly inserted nodes.
330- *
331- * @discussion Nodes are first inserted into the editing store, then the completed store is replaced by a deep copy
332- * of the editing nodes. The delegate is invoked on the main thread.
333- */
334- - (void )_insertNodes : (NSArray *)nodes atIndexPaths : (NSArray *)indexPaths andNotifyDelegate : (BOOL )shouldNotifyDelegate withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
335- {
336- void (^completionBlock)(NSArray *nodes, NSArray *indexPaths) = nil ;
337- if (shouldNotifyDelegate) {
338- completionBlock = ^(NSArray *nodes, NSArray *indexPaths) {
339- if (_delegateDidInsertNodes)
340- [_delegate dataController: self didInsertNodes: nodes atIndexPaths: indexPaths withAnimationOptions: animationOptions];
341- };
342- }
343-
344- [self insertNodes: nodes ofKind: ASDataControllerRowNodeKind atIndexPaths: indexPaths completion: completionBlock];
288+ [self insertNodes: nodes ofKind: ASDataControllerRowNodeKind atIndexPaths: indexPaths completion: ^(NSArray *nodes, NSArray *indexPaths) {
289+ if (_delegateDidInsertNodes)
290+ [_delegate dataController: self didInsertNodes: nodes atIndexPaths: indexPaths withAnimationOptions: animationOptions];
291+ }];
345292}
346293
347294/* *
@@ -358,46 +305,18 @@ - (void)_deleteNodesAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASD
358305 }];
359306}
360307
361- /* *
362- * Inserts sections, represented as arrays, into the backing store at the given indicies and doesn't notify the delegate.
363- *
364- * @discussion The section arrays are inserted into the editing store, then a deep copy of the sections are inserted
365- * in the completed store on the main thread.
366- */
367- - (void )_insertSections : (NSMutableArray *)sections atIndexSet : (NSIndexSet *)indexSet
368- {
369- [self _insertSections: sections atIndexSet: indexSet andNotifyDelegate: NO withAnimationOptions: 0 ];
370- }
371-
372- /* *
373- * Inserts sections, represented as arrays, into the backing store at the given indicies and doesn't notify the delegate.
374- *
375- * @discussion The section arrays are inserted into the editing store, then a deep copy of the sections are inserted
376- * in the completed store on the main thread.
377- */
378- - (void )_insertSections : (NSMutableArray *)sections atIndexSet : (NSIndexSet *)indexSet withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
379- {
380- [self _insertSections: sections atIndexSet: indexSet andNotifyDelegate: YES withAnimationOptions: animationOptions];
381- }
382-
383308/* *
384309 * Inserts sections, represented as arrays, into the backing store at the given indicies and notifies the delegate.
385310 *
386311 * @discussion The section arrays are inserted into the editing store, then a deep copy of the sections are inserted
387312 * in the completed store on the main thread. The delegate is invoked on the main thread.
388313 */
389- - (void )_insertSections : (NSMutableArray *)sections atIndexSet : (NSIndexSet *)indexSet andNotifyDelegate : ( BOOL ) shouldNotifyDelegate withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
314+ - (void )_insertSections : (NSMutableArray *)sections atIndexSet : (NSIndexSet *)indexSet withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
390315{
391-
392- void (^completionBlock)(NSArray *sections, NSIndexSet *indexSet) = nil ;
393- if (shouldNotifyDelegate) {
394- completionBlock = ^(NSArray *sections, NSIndexSet *indexSet) {
395- if (_delegateDidInsertSections)
396- [_delegate dataController: self didInsertSections: sections atIndexSet: indexSet withAnimationOptions: animationOptions];
397- };
398- }
399-
400- [self insertSections: sections ofKind: ASDataControllerRowNodeKind atIndexSet: indexSet completion: completionBlock];
316+ [self insertSections: sections ofKind: ASDataControllerRowNodeKind atIndexSet: indexSet completion: ^(NSArray *sections, NSIndexSet *indexSet) {
317+ if (_delegateDidInsertSections)
318+ [_delegate dataController: self didInsertSections: sections atIndexSet: indexSet withAnimationOptions: animationOptions];
319+ }];
401320}
402321
403322/* *
@@ -442,17 +361,17 @@ - (void)initialDataLoadingWithAnimationOptions:(ASDataControllerAnimationOptions
442361 }];
443362}
444363
445- - (void )reloadDataWithCompletion : (void (^)())completion
364+ - (void )reloadDataWithAnimationOptions : (ASDataControllerAnimationOptions) animationOptions completion : (void (^)())completion
446365{
447- [self _reloadDataSynchronously :NO completion: completion];
366+ [self _reloadDataWithAnimationOptions: animationOptions synchronously :NO completion: completion];
448367}
449368
450- - (void )reloadDataImmediately
369+ - (void )reloadDataImmediatelyWithAnimationOptions : (ASDataControllerAnimationOptions) animationOptions
451370{
452- [self _reloadDataSynchronously :YES completion: nil ];
371+ [self _reloadDataWithAnimationOptions: animationOptions synchronously :YES completion: nil ];
453372}
454373
455- - (void )_reloadDataSynchronously : (BOOL )synchronously completion : (void (^)())completion
374+ - (void )_reloadDataWithAnimationOptions : (ASDataControllerAnimationOptions) animationOptions synchronously : (BOOL )synchronously completion : (void (^)())completion
456375{
457376 [self performEditCommandWithBlock: ^{
458377 ASDisplayNodeAssertMainThread ();
@@ -474,7 +393,12 @@ - (void)_reloadDataSynchronously:(BOOL)synchronously completion:(void (^)())comp
474393 LOG (@" Edit Transaction - reloadData" );
475394
476395 // Remove everything that existed before the reload, now that we're ready to insert replacements
477- [self deleteAllNodesOfKind: ASDataControllerRowNodeKind];
396+ NSArray *indexPaths = ASIndexPathsForMultidimensionalArray (_editingNodes[ASDataControllerRowNodeKind]);
397+ [self _deleteNodesAtIndexPaths: indexPaths withAnimationOptions: animationOptions];
398+
399+ NSMutableArray *editingNodes = _editingNodes[ASDataControllerRowNodeKind];
400+ NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc ] initWithIndexesInRange: NSMakeRange (0 , editingNodes.count)];
401+ [self _deleteSectionsAtIndexSet: indexSet withAnimationOptions: animationOptions];
478402
479403 [self willReloadData ];
480404
@@ -484,19 +408,12 @@ - (void)_reloadDataSynchronously:(BOOL)synchronously completion:(void (^)())comp
484408 [sections addObject: [[NSMutableArray alloc ] init ]];
485409 }
486410
487- [self _insertSections: sections atIndexSet: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange (0 , sectionCount)]];
411+ [self _insertSections: sections atIndexSet: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange (0 , sectionCount)] withAnimationOptions: animationOptions ];
488412
489- [self _batchLayoutNodes: updatedNodes atIndexPaths: updatedIndexPaths];
413+ [self _batchLayoutNodes: updatedNodes atIndexPaths: updatedIndexPaths withAnimationOptions: animationOptions ];
490414
491- if (_delegateDidReloadData || completion) {
492- [_mainSerialQueue performBlockOnMainThread: ^{
493- if (_delegateDidReloadData) {
494- [_delegate dataControllerDidReloadData: self ];
495- }
496- if (completion) {
497- completion ();
498- }
499- }];
415+ if (completion) {
416+ dispatch_async (dispatch_get_main_queue (), completion);
500417 }
501418 };
502419
0 commit comments