Skip to content
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

Update loose equal function, check toString value for primitive type (fix #4514) #4528

Merged
merged 1 commit into from
Dec 21, 2016
Merged

Update loose equal function, check toString value for primitive type (fix #4514) #4528

merged 1 commit into from
Dec 21, 2016

Conversation

defcc
Copy link
Member

@defcc defcc commented Dec 20, 2016

fix #4514

const isObjectB = isObject(b)
if (isObjectA && isObjectB) {
return JSON.stringify(a) === JSON.stringify(b)
} else if (!isObjectA && !isObjectB) {
Copy link
Member

Choose a reason for hiding this comment

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

LGTM.
(It may be better to check more strictly ... 😉 )

Copy link
Contributor

@dsonet dsonet Dec 21, 2016

Choose a reason for hiding this comment

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

It's loose equal. Which I think just add the 0 check is enough for primitive type cases. So we can skip unnecessary methods invoke here and keep it simple.

if(a === 0) {
  a = '0'
}
if(b === 0) {
  b = '0'
}
return a == b || (
     isObject(a) && isObject(b)
      ? JSON.stringify(a) === JSON.stringify(b)
      : false
 )

Copy link
Member Author

@defcc defcc Dec 21, 2016

Choose a reason for hiding this comment

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

We need strict equality for primitive type, e.g., '0' is equal to false. I'll update the test case like bellow

new Vue({
  data: {
    val: false,
    test: 0
  },
  template:
    '<div>' +
      '<input type="radio" value="" v-model="test">' +
      '<input type="radio" value="0" v-model="test">' +
      '<input type="radio" :value="val" v-model="test">' +
    '</div>'
}).$mount('#app')

Copy link
Member Author

Choose a reason for hiding this comment

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

done via #4542

@yyx990803 yyx990803 merged commit 56bfa1d into vuejs:dev Dec 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sometime select's event does't work when option's vlaue in ('',0)
4 participants