Skip to content

Commit 23a1459

Browse files
committed
refactor: adjust #7941 for slots unification
1 parent fb6aa06 commit 23a1459

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/core/vdom/create-functional-component.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ export function FunctionalRenderContext (
4848
this.children = children
4949
this.parent = parent
5050
this.listeners = data.on || emptyObject
51-
this.scopedSlots = data.scopedSlots || emptyObject
5251
this.injections = resolveInject(options.inject, parent)
5352
this.slots = () => resolveSlots(children, parent)
5453

54+
Object.defineProperty(this, 'scopedSlots', {
55+
enumerable: true,
56+
get () {
57+
return normalizeScopedSlots(data.scopedSlots, this.slots())
58+
}
59+
})
60+
5561
// support for compiled functional template
5662
if (isCompiled) {
5763
// exposing $options for renderStatic()

src/core/vdom/helpers/normalize-scoped-slots.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function normalizeScopedSlots (
2121
}
2222
res._normalized = true
2323
}
24+
// expose normal slots on scopedSlots
2425
if (normalSlots !== emptyObject) {
2526
for (const key in normalSlots) {
2627
res[key] = () => normalSlots[key]

test/unit/features/options/functional.spec.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,25 @@ describe('Options functional', () => {
7979
document.body.removeChild(vm.$el)
8080
})
8181

82-
it('should expose data.scopedSlots as scopedSlots', () => {
82+
it('should expose scopedSlots on render context', () => {
8383
const vm = new Vue({
84-
template: '<div><wrap><p slot-scope="a">{{ a }}</p></wrap></div>',
84+
template: '<div><wrap>foo<p slot="p" slot-scope="a">{{ a }}</p></wrap></div>',
8585
components: {
8686
wrap: {
8787
functional: true,
88-
render (h, { scopedSlots, data }) {
89-
expect(data.scopedSlots).toBe(scopedSlots)
90-
return data.scopedSlots.default('a')
88+
render (h, { scopedSlots }) {
89+
return [
90+
// scoped
91+
scopedSlots.p('a'),
92+
// normal slot content should be exposed as well
93+
scopedSlots.default()
94+
]
9195
}
9296
}
9397
}
9498
}).$mount()
9599

96-
expect(vm.$el.textContent).toBe('a')
100+
expect(vm.$el.textContent).toBe('afoo')
97101
})
98102

99103
it('should support returning more than one root node', () => {

0 commit comments

Comments
 (0)