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(provide): Merges symbol provides #7926

Merged
merged 3 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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