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 #6093, inject should not be merged with Object.create #6098

Closed
wants to merge 2 commits into from

Conversation

jkzing
Copy link
Member

@jkzing jkzing commented Jul 13, 2017

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:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:
fix #6093

Object.create is not adding 'own property' to the object, which caused injections not injected properly.😭

@javoski
Copy link
Member

javoski commented Jul 14, 2017

Thanks for the PR.
Actually there's no need to add another merge strategy function, it's an issue about using Object.keys() to iterate inject object while using for...in on other options. (Object.keys() will not enumerates properties in the prototype chain, but for...in does).
See https://github.com/vuejs/vue/blob/dev/src/core/instance/inject.js#L21

So my suggestion is:

strats.props =
strats.methods =
strats.inject =
strats.computed = function (parentVal: ?Object, childVal: ?Object): ?Object {
  if (!parentVal) return childVal
  const ret = Object.create(null)
  extend(ret, parentVal)
  if (childVal) extend(ret, childVal)
  return ret
}
// Just delete this line will fix that issue :
if (!childVal) return Object.create(parentVal || null)

@jkzing
Copy link
Member Author

jkzing commented Jul 14, 2017

@javoski You are right, I did think about that too. But I just didn't have the confident to remove that line directly. (I was afraid it's using Object.create for a reason)

Anyway, If it works totally OK without Object.create, it's better to merge your PR, and feel free to close this one when merging it.

@yyx990803
Copy link
Member

Thanks, #6093 seems to be a simpler fix.

@yyx990803 yyx990803 closed this Jul 19, 2017
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.

Inject option in mixin no longer works
3 participants