IGListKit/Source/IGListIndexSetResult.h
Ryan Nystrom b5aa5e3900 Replace diff result API for batch updates
Summary:
Replacing the move+update API with a batch-updates-safe API on the diff results object. This makes using the diff results w/out the rest of IGListKit infra much easier when working with `UITableView` or `UICollectionView`.

- Added unit tests
- Removed outdated unit tests

Reviewed By: dshahidehpour

Differential Revision: D4065798

fbshipit-source-id: 30da8a7b483d56d5acc497da9320dc07a6d0b7ad
2016-10-26 11:59:13 -07:00

76 lines
2 KiB
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 <Foundation/Foundation.h>
#import <IGListKit/IGListMoveIndex.h>
NS_ASSUME_NONNULL_BEGIN
/**
Result object returned when diffing with indexes.
*/
@interface IGListIndexSetResult : NSObject
/**
Indexes inserted into the new collection.
*/
@property (nonatomic, strong, readonly) NSIndexSet *inserts;
/**
Indexes deleted from the old collection.
*/
@property (nonatomic, strong, readonly) NSIndexSet *deletes;
/**
Indexes in the new collection that need updated.
*/
@property (nonatomic, strong, readonly) NSIndexSet *updates;
/**
Moves from an index in the old collection to an index in the new collection.
*/
@property (nonatomic, copy, readonly) NSArray<IGListMoveIndex *> *moves;
/**
Convenience to query if the result has any changes.
@return YES if the result has changes, NO otherwise.
*/
- (BOOL)hasChanges;
/**
Fetch the index of the object with identifier before the diff.
@param identifier The diff identifier of the object. See -[IGListDiffable diffIdentifier].
@return The index of the object before the diff, or NSNotFound.
*/
- (NSUInteger)oldIndexForIdentifier:(id<NSObject>)identifier;
/**
Fetch the index of the object with identifier after the diff.
@param identifier The diff identifier of the object. See -[IGListDiffable diffIdentifier].
@return The index of the object after the diff, or NSNotFound.
*/
- (NSUInteger)newIndexForIdentifier:(id<NSObject>)identifier;
/**
Create a new result object with operations safe for use in UITableView and UICollectionView batch updates.
*/
- (IGListIndexSetResult *)resultForBatchUpdates;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END