Comments (10)
@ValCanBuild Hi, I was thinking so too. I 'd like to expose comparison callback instead of implicitly relying on Hashable.
from deepdiff.
@ValCanBuild I haven't yet submitted a pull request for this but I've changed the UICollectionView extension to be reload<T: DiffAware>
and it is working fine. I guess I should submit that PR along with the same change for UITableView...
from deepdiff.
@archagon Hi, it is because currently I use a hashValue
as a key to manage uniqueness of objects, so a replacement occurs only if the key remains but the content changes, see #16
It works a bit differently from Wagner Fischer. I will see if I have time to make this more intuitive
from deepdiff.
@onmyway133 isn't the way you're using hashvalue technically incorrect? You're using it as a unique identifier for an object and the two aren't necessarily the same thing.
A hash of a struct should be computed based on all its properties, not just one. This makes it hard to handle replacement operations. I like what the android DiffUtil library does in this case where it gives the library user the callback to determine whether two items are the same and if they are, then it compares their contents to figure out if they are the same.
This leads to a very straightforward implementation:
- Have a unique id for each object (up to developer to choose)
- Use that id to determine if two items are the same in the context of DeepDiff
- If they aren't, then this is either an insertion or deletion. Stop here
- If they are, then check if their contents are the same (this is where just using Equatable would work)
- If they are, then nothing has changed
- If they aren't then a change has occured.
Any chance something like this could be implemented?
from deepdiff.
@archagon Hi, I introduced DiffAware protocol to make diff changes more explicit https://github.com/onmyway133/DeepDiff/releases/tag/2.0.0. Can you check if that works for you ?
from deepdiff.
@onmyway133 shouldn't DiffAware be constrained to a Hashable
?
from deepdiff.
@ValCanBuild I can't see any reason for that, would you care to enlighten me?
from deepdiff.
@snoozemoose well in order to use the reload
extension on TableViews/CollectionViews the item must be Hashable
. So making your data only conform to DiffAware
makes it usable in the diff
part of the algorithm but not in the applying changes part.
So either DiffAware
needs to be made Hashable or reload
function Hashable constraint must ve removed.
from deepdiff.
PR is submitted now: #31
from deepdiff.
❤️
from deepdiff.
Related Issues (20)
- Support Swift Package Manager HOT 6
- Example using two String arrays HOT 6
- what about if people have String `ID` not `Int` HOT 1
- attempt to delete row 2 from section 0 which only contains 1 rows before the update
- Troubles with API HOT 2
- [Bug] Carthage update failed HOT 1
- Is the documentation correct for diff("abcd", "adbc")? HOT 1
- Add Swift's CollectionDifference to Performance tests HOT 1
- Build Library For Distribution (swift compatibility) HOT 8
- Is there any reason for this library to be MacOS 10.11+? HOT 2
- Crash: attempt to delete item 20 from section 0 which only contains 20 items before the update HOT 3
- How to use diffId when diffing SQL entities? HOT 3
- Error adding new section to collection view HOT 1
- Xcode 12 deployment warning when using Swift Package Manager HOT 2
- lifetime of Heckel? HOT 3
- Should I implement diifId If object is already conforming Hashable? HOT 1
- Unsupported watchOS version for PackageDescription version HOT 4
- Wrong version number 3.2.3 HOT 2
- Replace<T>' initializer is inaccessible due to 'internal' protection level HOT 1
- How to apply the changes to old-array HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepdiff.