Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Change IGListDiff result type to generic object with array of operations #694

Open
rnystrom opened this issue Apr 24, 2017 · 2 comments
Labels

Comments

@rnystrom
Copy link
Contributor

Had a shower-thought this morning: what if we change the result produced by IGListDiff(...) to be a generic result object with an array of operations (delete/insert/reload/move)?

Why?

There are currently too many things doing essentially the same stuff:

There's a lot of duplication going on here. I think we can clean it up:

Proposal

Create a generic "operation" object:

@interface IGListOperation<ObjectType>: NSObject
@property (nonatomic, strong, readonly) ObjectType from;
@property (nonatomic, strong, readonly) ObjectType to;
@property (nonatomic, assign, readonly) IGListOperationType type; // delete, insert, move, update
@end

Then we create a new result object:

@interface IGListDiffResult<ObjectType>: NSObject
@property (nonatomic, strong, readonly) NSArray<IGListOperation<ObjectType> *> *operations;
@end

I'd also love to restore diff statistics (like clocking the time it takes to diff). We used to collect this data.

We could also add back APIs like -[IGListDiffResult inserts] that just query an internal map of operation types to operations. Might be convenient?

Considerations

  • We merge diff results with other coalesced operations. This still has to happen.
  • Operations should implement isEqual: and hash so we can add and unique them in NSSets

Questions

  • Can we intermix NSIndexPath and NSInteger with generic types?
    • I don't think so, and if even if we could, I don't think we could right a proper hash and isEqual for the operation
  • Is unpacking NSNumber with integerValue when enumerating operations a concern at all? The perf overhead should be minuscule, but it does exist
@zhubofei
Copy link

@rnystrom Maybe use Set instead of Array for operations?

@rnystrom
Copy link
Contributor Author

@zhubofei array is the cleanest way to interop with other methods expecting arrays. Plus the diff internals should already guarantee there aren’t dupe operations.

Is there another reason we should use a Set?

Sent with GitHawk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants