Skip to content

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