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

Add update support for diff algorithm #9

Closed
Tayphoon opened this issue Oct 25, 2019 · 6 comments
Closed

Add update support for diff algorithm #9

Tayphoon opened this issue Oct 25, 2019 · 6 comments

Comments

@Tayphoon
Copy link

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.

@ra1028
Copy link
Owner

ra1028 commented Nov 7, 2019

This is the same specification as Apple's official DiffableDataSource, because it uses "Hashable" instead of "Identifiable".

@ollitapa
Copy link

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)
    }
}

@winstondu
Copy link

winstondu commented Feb 21, 2020

@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.

#18

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.

@ollitapa
Copy link

@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.

@ollitapa
Copy link

Btw, it's curious that SwiftUI List seems to use Identifiable protocol for "differenceIdentifier" and view graph equality for the "isContentEqual"

@winstondu
Copy link

@ollitapa , agreed. I don't understand why Apple's official DiffableDataSources uses the Hashable protocol when they have the Identifiable Protocol

@ra1028 ra1028 closed this as completed Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants