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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(functional): add scopedSlots to context in functional components #7941

Merged
merged 3 commits into from
Jan 9, 2019
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
1 change: 1 addition & 0 deletions src/core/vdom/create-functional-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function FunctionalRenderContext (
this.children = children
this.parent = parent
this.listeners = data.on || emptyObject
this.scopedSlots = data.scopedSlots || emptyObject
this.injections = resolveInject(options.inject, parent)
this.slots = () => resolveSlots(children, parent)

Expand Down
17 changes: 17 additions & 0 deletions test/unit/features/options/functional.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ describe('Options functional', () => {
expect(bar).toHaveBeenCalledWith('bar')
})

it('should expose data.scopedSlots as scopedSlots', () => {
const vm = new Vue({
template: '<div><wrap><p slot-scope="a">{{ a }}</p></wrap></div>',
components: {
wrap: {
functional: true,
render (h, { scopedSlots, data }) {
expect(data.scopedSlots).toBe(scopedSlots)
return data.scopedSlots.default('a')
}
}
}
}).$mount()

expect(vm.$el.textContent).toBe('a')
})

it('should support returning more than one root node', () => {
const vm = new Vue({
template: `<div><test></test></div>`,
Expand Down
3 changes: 2 additions & 1 deletion types/options.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Vue, CreateElement, CombinedVueInstance } from "./vue";
import { VNode, VNodeData, VNodeDirective } from "./vnode";
import { VNode, VNodeData, VNodeDirective, ScopedSlot } from "./vnode";

type Constructor = {
new (...args: any[]): any;
Expand Down Expand Up @@ -123,6 +123,7 @@ export interface RenderContext<Props=DefaultProps> {
data: VNodeData;
parent: Vue;
listeners: { [key: string]: Function | Function[] };
scopedSlots: { [key: string]: ScopedSlot };
injections: any
}

Expand Down
1 change: 1 addition & 0 deletions types/test/options-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Vue.component('functional-component', {
context.slots();
context.data;
context.parent;
context.scopedSlots;
context.listeners.click;
return createElement("div", {}, context.children);
}
Expand Down