-
Notifications
You must be signed in to change notification settings - Fork 4
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
DataChange not dispatched when value in List changes #13
Comments
Yes. The goal of this was to be able to use different animation when the data of an item in the list changes vs. when one item was removed and a new item was inserted the same position. By default, when just using equality, it is never emitted. For example, when you have a List of type class DataObjectListDiff extends diffutil.ListDiffDelegate<DataObject> {
DataObjectListDiff(List<DataObject> oldList, List<DataObject> newList)
: super(oldList, newList);
@override
bool areContentsTheSame(int oldItemPosition, int newItemPosition) {
return equalityChecker(oldList[oldItemPosition], newList[newItemPosition]);
}
@override
bool areItemsTheSame(int oldItemPosition, int newItemPosition) {
return oldList[oldItemPosition].id == newList[newItemPosition].id;
}
} And then call diffutil
.calculateDiff<DataObject>(DataObjectListDiff(
[DataObject(id: 1, payload: 0)], [DataObject(id: 1, payload: 1)]))
.getUpdatesWithData();
|
Thank you, this is exactly what I was looking for. To gain some benefit for others out of this issue, perhaps you could add the example you've provided above to the documentation? 😀 |
Yes, I put it on my todo list :) |
Wow great question! I just had this issue using this fantastic library. I am using it to compare lists of strings (tokenized texts)... I don't completely understand the reasoning between equality and identity. How would I go about with simple string lists? Perhaps if the comparison is between simple lists, change should be emitted by default perhaps?
|
PS it is also unclear from the example how we can get changes for the basic example Extending like this does not work. Perhaps we should have separate calls for Lists and Objects?
|
The changes are really meant for cases when you have a meaningful identity. Like if you have a User-Object with the content {
"id": 1
"name" : "Joe"
}
and {
"id": 1
"name" : "Peter"
}
It's easy to detect that that's the same user but with a different name. If you don't have a field like It might be possible the do a post-process step where inserts and removals are merged to change operations afterward - but it's not implemented as of yet. But if you really just need strings, maybe check out Google's diff-match-patch library. It's similar to diffutil but focused purely on text-maybe this will help you. |
Ah ok. Changes for a simple list diff would have been nice, bit I guess I can convert a list of strings to a list of plain objects with an id... |
PS if we could have an example with objects that would be fab :) |
Thanks for the feedback. Yeah I'll update documentation and more examples soon. |
Yes, unfortunately I don't really see a way of implementing that. The algorithm, that most of these diff-libraries are based on, is Myer's algorithm and it does not support change operations per se- It's just that if you have a unique ID, this can be added pretty easily. For general support without IDs the algorithm would need to be reworked (not within by abilities, to be honest) or a post-processing step, similar to batching, would be necessary. |
Actually I got it to work without an id, though I'm not 100% sure how safe it is.
|
I think this might work, yes. It's important to understand that If you have an implementation where |
Hi, I'm trying to understanding the
change
callback on theDataDiffUpdate
class.Why does
return
I would have assumed a single
DataChange
.Can you please explain when a
DataChange
will be created?The text was updated successfully, but these errors were encountered: