-
Notifications
You must be signed in to change notification settings - Fork 70
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
Add update support for diff algorithm #9
Comments
This is the same specification as Apple's official DiffableDataSource, because it uses "Hashable" instead of "Identifiable". |
Just run into this issue. Could you consider introducing a wrapper struct to help out? /// A struct whose hash value is based on
/// the differenceIdentifier of the content.
public struct Diffable<Item: Differentiable & Equatable>: Hashable {
public var content: Item
public init(_ content: Item) {
self.content = content
}
public func hash(into hasher: inout Hasher) {
hasher.combine(content.differenceIdentifier)
}
} |
@ollitapa , I have a PR over from my fork of this library that solves this issue. You can feel free to pull from my fork until it gets merged in. The larger issue, I think, is Apple's engineers clearly wrote their library wrong (they don't have any updates). So the question is whether we should have this library conform to Apple's mistakes, or we do it right. |
@winstondu Seems good! I agree that the Apple provided API is a bit confusing, so I opted to use the Diffable wrapper I showed above. I thought it worked fine, but now that you mention the issue, with the hashValue handling, I can see that those updates are also needed. |
Btw, it's curious that SwiftUI List seems to use Identifiable protocol for "differenceIdentifier" and view graph equality for the "isContentEqual" |
@ollitapa , agreed. I don't understand why Apple's official DiffableDataSources uses the Hashable protocol when they have the |
DifferenceKit use ContentEquatable protocol to produce items update. DataSource wrap items into struct which implement Differentiable protocol. In fact diff algorithm never produce update events, there is only one way - call reload method in DataSource. We would like to implement ContentEquatable for DataSource items and get ChangeSet with updates.
The text was updated successfully, but these errors were encountered: