Closed Odonno closed 6 years ago
At least, there is this topic https://stackoverflow.com/questions/1652897/how-do-i-compare-the-fields-properties-between-pocos
But I hope there is a library for it.
Ah, good catch! I'm not aware of a solution to this that covers all cases and is performant enough to be used across the board. Having said that, I'll try to do some research when I get a chance.
If nothing has ever been done before. Let's just take the solution from stackoverflow and see if it fits our needs.
@mhusainisurge I made a PR for this. I was inspired by the stackoverflow solution and made some changes to fit our needs. But the solution looks pretty simple : use reflexion to get properties of the State and compare them each one against the other to find a difference.
I added some unit tests in order to test the
DistinctUntilChanged
observable but one thing I notice is that if we observe the object directly, the distinct is made on the reference and not the properties so even if the state have unchanged property values, the observable considers the object as new and not distinct.I solved it by overriding the
Equals
method. https://github.com/Odonno/ReduxSimple/blob/0a3167636e3383a4ce7fda9d628ea0740cc2886f/ReduxSimple.UnitTests/Models.cs#L27But it feels odd to override the method since the object can be used in other part of dev apps. So, my questions are :
DistinctUntilChanged
method?Maybe @mhusainisurge have an idea?