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: improve slots mounting option #821

Closed
wants to merge 4 commits into from
Closed

Conversation

38elements
Copy link
Contributor

@38elements 38elements commented Jul 12, 2018

This resolves #793.
This is related to #813.
This does not reslove #827.

@38elements
Copy link
Contributor Author

38elements commented Jul 12, 2018

I will add some tests and improvements within 3 days.

@38elements 38elements force-pushed the slots branch 6 times, most recently from 955689d to 4fc7323 Compare July 14, 2018 04:11
@38elements 38elements changed the title [WIP]fix: improve slots mounting option fix: improve slots mounting option Jul 14, 2018
@38elements 38elements force-pushed the slots branch 4 times, most recently from 962d5ef to da3e193 Compare July 15, 2018 02:59
slotValue: Component | string
): ?Array<VNode> {
if (typeof slotValue === 'string') {
const compiledResult = compileToFunctions(`<div>${slotValue}{{ }}</div>`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the empty interpolation {{ }}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand.
It is not necessary.
I thought the compileToFunctions raises an error if it dose not exist at #274.

@38elements
Copy link
Contributor Author

38elements commented Jul 18, 2018

I think it is necessary to add warning if compileToFunctions is not existing.
I will add them.

// it is not necessary to check compileToFunctions.
const compiledResult = compileToFunctions(`<div>${slotValue}</div>`)
const _staticRenderFns = vm._renderProxy.$options.staticRenderFns
vm._renderProxy.$options.staticRenderFns = compiledResult.staticRenderFns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you save the renderFunctions and then reassign?

() => {
const wrapper1 = mount(ComponentWithSlots, { slots: { default: 'foo<span>123</span>{{ foo }}' }})
expect(wrapper1.find('main').html()).to.equal('<main>foo<span>123</span>bar</main>')
const wrapper2 = mount(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}2' }})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is how slots should behave. foo should not be resolved using the child vm that it's rendered in. If it uses any instance to resolve foo on, it should be the root instance. But I don't think we should support any variables in the slots option as it adds too much complexity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry.
Your pointing out is correct.
I misunderstood about it.

return [vm.$createElement(slotValue)]
}

export default function createRenderSlot (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of replacing the renderSlot alias? Does this solve the issue of parent being undefined?

@38elements 38elements closed this Jul 19, 2018
@38elements 38elements deleted the slots branch July 23, 2018 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$parent of a child component defined on a slot, reference to itself
2 participants