Skip to content

Conversation

@intersrc
Copy link

Sometimes, val & old are objects, like { label, value }, val !== old is true, but they have same label & value, this may cause a dead loop.
It's better to use a deep equal here.

@sagalbot
Copy link
Owner

sagalbot commented Dec 6, 2017

@intersrc thanks! Could you add a test to cover that case?

@intersrc
Copy link
Author

intersrc commented Dec 7, 2017

The test added. Now use val !== old will make tests die.
There is a small problem: if that happened, we can't locate which test is broken because of the dead loop.

@intersrc
Copy link
Author

intersrc commented Dec 7, 2017

Solved.

this.onChange ? this.onChange(val) : null
} else {
this.onChange && val !== old ? this.onChange(val) : null
this.onChange && JSON.stringify(val) !== JSON.stringify(old) ? this.onChange(val) : null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good comparison because order of properties can be different but values can be equal, so as a result comparison will fail.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified.

@skjnldsv
Copy link

This is really an issue that needs to be fixed :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants