wip: optimize expose
This commit is contained in:
parent
a603d56970
commit
b79a06c605
@ -95,4 +95,50 @@ describe('api: expose', () => {
|
|||||||
expect(childRef.value.bar).toBe(2)
|
expect(childRef.value.bar).toBe(2)
|
||||||
expect(childRef.value.baz).toBeUndefined()
|
expect(childRef.value.baz).toBeUndefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('options: empty', () => {
|
||||||
|
const Child = defineComponent({
|
||||||
|
render() {},
|
||||||
|
expose: [],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
foo: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const childRef = ref()
|
||||||
|
const Parent = {
|
||||||
|
setup() {
|
||||||
|
return () => h(Child, { ref: childRef })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const root = nodeOps.createElement('div')
|
||||||
|
render(h(Parent), root)
|
||||||
|
expect(childRef.value).toBeTruthy()
|
||||||
|
expect('foo' in childRef.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('options: empty + setup context', () => {
|
||||||
|
const Child = defineComponent({
|
||||||
|
render() {},
|
||||||
|
expose: [],
|
||||||
|
setup(_, { expose }) {
|
||||||
|
expose({
|
||||||
|
foo: 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const childRef = ref()
|
||||||
|
const Parent = {
|
||||||
|
setup() {
|
||||||
|
return () => h(Child, { ref: childRef })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const root = nodeOps.createElement('div')
|
||||||
|
render(h(Parent), root)
|
||||||
|
expect(childRef.value).toBeTruthy()
|
||||||
|
expect(childRef.value.foo).toBe(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -743,11 +743,19 @@ export function applyOptions(
|
|||||||
onUnmounted(unmounted.bind(publicThis))
|
onUnmounted(unmounted.bind(publicThis))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!asMixin && expose) {
|
if (isArray(expose)) {
|
||||||
const exposed = instance.exposed || (instance.exposed = proxyRefs({}))
|
if (!asMixin) {
|
||||||
expose.forEach(key => {
|
if (expose.length) {
|
||||||
exposed[key] = toRef(publicThis, key as any)
|
const exposed = instance.exposed || (instance.exposed = proxyRefs({}))
|
||||||
})
|
expose.forEach(key => {
|
||||||
|
exposed[key] = toRef(publicThis, key as any)
|
||||||
|
})
|
||||||
|
} else if (!instance.exposed) {
|
||||||
|
instance.exposed = EMPTY_OBJ
|
||||||
|
}
|
||||||
|
} else if (__DEV__) {
|
||||||
|
warn(`The \`expose\` option is ignored when used in mixins.`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user