freezed icon indicating copy to clipboard operation
freezed copied to clipboard

Comparing two instances of models' properties and find out which one was changed.

Open Lazizbek97 opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] When we have a model and it has hundreds of properties, we really feel frustrated while checking whether its' instances are the same or not. Actually checking whether two instances are the same or not, is easy with freezed, equitable. But checking every property of it and figuring out which property has been changed is really hard code and much work. Maybe there is any other ways which is very simple but I don't know. if so, please let me know about it. I really need it.

Describe the solution you'd like Any methods inside freezed check two instances, and return changed properties with names and values. Or more detailed way.

Lazizbek97 avatar Sep 08 '22 13:09 Lazizbek97

In what context do you need to know how the objects differ?

rrousselGit avatar Sep 08 '22 16:09 rrousselGit

In what context do you need to know how the objects differ?

Which properties of two objects are different? Imagine, I have two instances of the user model, which has 100 properties. one is changed by the user on the editing page. Now we have to know which property has been changed and let the backend know about it. At the moment I'm checking every property and comparing it with the old model instance. It's really hard code. I need somehow an easier way.

Lazizbek97 avatar Sep 09 '22 05:09 Lazizbek97

So the context is about sending only the diff to the backend?

You could compare the JSON output of two objects instead. Such as by using https://pub.dev/packages/json_diff

rrousselGit avatar Sep 09 '22 09:09 rrousselGit

So the context is about sending only the diff to the backend?

You could compare the JSON output of two objects instead. Such as by using https://pub.dev/packages/json_diff

Great! I didn't know that package existed. Anyway, if freezed also supports that function(json patching). That would be great.

Lazizbek97 avatar Sep 09 '22 09:09 Lazizbek97

Considering there's a good-enough workaround, I don't plan on implementing this for now.

rrousselGit avatar Sep 27 '22 13:09 rrousselGit