How to avoid triggering `dateChanged` method when `date` value is set to a new `Date` instance with the same date (SOLVED)

I am struggling with a bindable date property of type Date | null in one of my components.

When I set that property from one Date value to an other Date value, the dateChanged method in the view-model is triggered, even if the underlying dates in those (different) Date instances are exactly the same. I would like to avoid that.

Is there an elegant way to fix this? Can it be done with a binding behavior, for example? If so, are there any coding examples available somewhere which demonstrate how such a custom binding behavior could be implemented?

1 Like

Maybe I’m thinking too difficult.

I’ll just add the check for equal getTime() values of the old and the new date values at the beginning of the dateChanged method and immediately exit the method if they are equal.

1 Like