IGListKit/Source/Internal/IGListBatchUpdates.m
Ryan Nystrom a15ea08614 Move section controller mutation API to object provided in update block
Summary:
We constantly have random bugs pop up when mutations are made outside of a batch update. This change restricts the mutation API to a batch context object (which is just an `IGListAdapter`) so they can only be done **inside an update block**.

- Fixed open source project
- Confirmed open source examples build
- Updated all of Instagram.app to use this API
- Changelog breaking changes entry

Fixes #392

Reviewed By: jessesquires

Differential Revision: D4754129

fbshipit-source-id: 11d32a0fac3e50c9edbb01e92a8a0c7b8a43cf2d
2017-03-22 12:46:49 -07:00

34 lines
960 B
Objective-C

/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "IGListBatchUpdates.h"
@implementation IGListBatchUpdates
- (instancetype)init {
if (self = [super init]) {
_sectionReloads = [NSMutableIndexSet new];
_itemInserts = [NSMutableSet new];
_itemMoves = [NSMutableSet new];
_itemDeletes = [NSMutableSet new];
_itemUpdateBlocks = [NSMutableArray new];
_itemCompletionBlocks = [NSMutableArray new];
}
return self;
}
- (BOOL)hasChanges {
return [self.itemUpdateBlocks count] > 0
|| [self.sectionReloads count] > 0
|| [self.itemInserts count] > 0
|| [self.itemMoves count] > 0
|| [self.itemDeletes count] > 0;
}
@end