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

fix #5997: refactor function registerRef #6039

Merged
merged 2 commits into from
Jul 7, 2017
Merged

fix #5997: refactor function registerRef #6039

merged 2 commits into from
Jul 7, 2017

Conversation

javoski
Copy link
Member

@javoski javoski commented Jul 6, 2017

fix #5997 .
When registering ref, if refs[key] is an array and ref is already in refs[key], then do nothing.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

refs[key] = [ref]
} else if (refs[key].indexOf(ref) < 0) {
// $flow-disable-line
refs[key].push(ref)
Copy link
Member Author

@javoski javoski Jul 6, 2017

Choose a reason for hiding this comment

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

It's seems that flow is a little weak to check array type, even codes below couldn't pass.

if (Array.isArray(refs[key])) {
  if (refs[key].indexOf(ref)) {
    refs[key].push(ref)
  }
}

So I added a suppress_comment option to .flowconfig.

@Kingwl
Copy link
Member

Kingwl commented Jul 6, 2017

please add the test case😁

@javoski
Copy link
Member Author

javoski commented Jul 6, 2017 via email

@yyx990803 yyx990803 merged commit 254d85c into vuejs:dev Jul 7, 2017
@javoski javoski deleted the component-ref branch July 11, 2017 07:25
@wuchuguang
Copy link

upgrade vue2.4.4
parent1
child ref="child"
loop child

parent1.$refs.child is ok
parent2.$refs.child is undefined

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.

Refs incorrect when using v-for and combining components and elements
4 participants