Skip to content

Commit

Permalink
fix(provide/inject): Merges symbol provides (#7926)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored and yyx990803 committed Dec 21, 2018
1 parent 5ab028a commit 1933ee8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/core/util/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import config from '../config'
import { warn } from './debug'
import { nativeWatch } from './env'
import { set } from '../observer/index'
import { hasSymbol } from '../util/index'

import {
ASSET_TYPES,
Expand Down Expand Up @@ -48,9 +49,15 @@ if (process.env.NODE_ENV !== 'production') {
function mergeData (to: Object, from: ?Object): Object {
if (!from) return to
let key, toVal, fromVal
const keys = Object.keys(from)

const keys = hasSymbol
? Reflect.ownKeys(from)
: Object.keys(from)

for (let i = 0; i < keys.length; i++) {
key = keys[i]
// in case the object is already observed...
if (key === '__ob__') continue
toVal = to[key]
fromVal = from[key]
if (!hasOwn(to, key)) {
Expand Down
26 changes: 26 additions & 0 deletions test/unit/features/options/inject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,32 @@ describe('Options provide/inject', () => {
}).$mount()
expect(vm.$el.textContent).toBe('123')
})

it('should merge symbol provide from mixins (functions)', () => {
const keyA = Symbol('foo')
const keyB = Symbol('bar')

const mixinA = { provide: () => ({ [keyA]: 'foo' }) }
const mixinB = { provide: () => ({ [keyB]: 'bar' }) }
const child = {
inject: {
foo: keyA,
bar: keyB
},
template: `<span/>`,
created () {
injected = [this.foo, this.bar]
}
}
new Vue({
mixins: [mixinA, mixinB],
render (h) {
return h(child)
}
}).$mount()

expect(injected).toEqual(['foo', 'bar'])
})
}

// GitHub issue #5223
Expand Down

0 comments on commit 1933ee8

Please sign in to comment.