Skip to content

Commit

Permalink
Update documentation for diff
Browse files Browse the repository at this point in the history
Summary:
Update documentation for diff to be in sync with ab890fc. Documentation update only, nothing to test.

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Closes #231

Differential Revision: D4211422

Pulled By: rnystrom

fbshipit-source-id: 9cb637e42300d9db173d99c1305845984d52ce7b
  • Loading branch information
antons authored and Facebook Github Bot committed Nov 20, 2016
1 parent 1a62e40 commit c48a39a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ You can return an array of _any_ type of data, as long as it conforms to `IGList

`IGListKit` uses an algorithm adapted from a paper titled [A technique for isolating differences between files](http://dl.acm.org/citation.cfm?id=359467&dl=ACM&coll=DL) by Paul Heckel. This algorithm uses a technique known as the *longest common subsequence* to find a minimal diff between collections in linear time `O(n)`. It finds all **inserts**, **deletes**, **updates**, and **moves** between arrays of data.

To add custom, diffable models, you need to conform to the `IGListDiffable` protocol and implement `diffIdentifier()` and `isEqual(_:)`.
To add custom, diffable models, you need to conform to the `IGListDiffable` protocol and implement `diffIdentifier()` and `isEqual(toDiffableObject:)`.

For an example, consider the following model:

Expand Down Expand Up @@ -165,7 +165,7 @@ extension User: IGListDiffable {
return primaryKey
}

func isEqual(object: Any?) -> Bool {
func isEqual(toDiffableObject object: Any?) -> Bool {
if let object = object as? User {
return name == object.name
}
Expand All @@ -176,7 +176,7 @@ extension User: IGListDiffable {

The algorithm will skip updating two `User` objects that have the same `primaryKey` and `name`, even if they are different instances! You now avoid unecessary UI updates in the collection view even when providing new instances.

> **Note:** Remember that `isEqual(_:)` should return `false` when you want to reload the cells in the corresponding section controller.
> **Note:** Remember that `isEqual(toDiffableObject:)` should return `false` when you want to reload the cells in the corresponding section controller.
### Diffing outside of IGListKit

Expand Down
4 changes: 2 additions & 2 deletions Source/IGListDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef NS_ENUM(NSInteger, IGListDiffOption) {
*/
IGListDiffPointerPersonality,
/**
Compare objects using `-[NSObject isEqual:]`.
Compare objects using `-[NSObject isEqualToDiffableObject:]`.
*/
IGListDiffEquality
};
Expand All @@ -38,7 +38,7 @@ typedef NS_ENUM(NSInteger, IGListDiffOption) {
@return A result object containing affected indexes.
*/
FOUNDATION_EXTERN IGListIndexSetResult *IGListDiff(NSArray<id<IGListDiffable> > *_Nullable oldArray,
FOUNDATION_EXTERN IGListIndexSetResult *IGListDiff(NSArray<id<IGListDiffable>> *_Nullable oldArray,
NSArray<id<IGListDiffable>> *_Nullable newArray,
IGListDiffOption option);

Expand Down
2 changes: 1 addition & 1 deletion Source/IGListDiff.mm
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static id IGListDiffing(BOOL returnIndexPaths,
}
break;
case IGListDiffEquality:
// use -[IGListDiffable isEqual:] between both version of data to see if anything has changed
// use -[IGListDiffable isEqualToDiffableObject:] between both version of data to see if anything has changed
// skip the equality check if both indexes point to the same object
if (n != o && ![n isEqualToDiffableObject:o]) {
entry->updated = YES;
Expand Down

0 comments on commit c48a39a

Please sign in to comment.