-
Notifications
You must be signed in to change notification settings - Fork 393
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
feat(template-compiler): implement handling for scoped slot directives in template #3077
Changes from all commits
52f0d2f
45c217d
90b9b0e
3c90967
4b9166d
e0e49fe
3cd6be4
812ff70
3e51fa9
188e84f
94edd67
3be71d6
505e592
4a426fe
3576c5e
1bbcbb4
21e7c11
54ef4b5
7840bfa
3a4edf5
2a95159
1798af7
ce36e81
8313089
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,9 @@ export interface TemplateCache { | |
} | ||
|
||
export interface SlotSet { | ||
[key: string]: VNodes; | ||
// Slot assignments by name | ||
slotAssignments: { [key: string]: VNodes }; | ||
owner?: VM; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The root vm will not have an owner for its slotset(its There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think this is a preferable approach to avoid allocating 2 empty objects for all the components that don't accept slots. |
||
} | ||
|
||
export const enum VMState { | ||
|
@@ -135,7 +137,8 @@ export interface VM<N = HostNode, E = HostElement> { | |
velements: VCustomElement[]; | ||
/** The component public properties. */ | ||
cmpProps: { [name: string]: any }; | ||
/** The mapping between the slot names and the slotted VNodes. */ | ||
/** Contains information about the mapping between the slot names and the slotted VNodes, and | ||
* the owner of the slot content. */ | ||
cmpSlots: SlotSet; | ||
/** The component internal reactive properties. */ | ||
cmpFields: { [name: string]: any }; | ||
|
@@ -301,7 +304,7 @@ export function createVM<HostNode, HostElement>( | |
velements: EmptyArray, | ||
cmpProps: create(null), | ||
cmpFields: create(null), | ||
cmpSlots: create(null), | ||
cmpSlots: { slotAssignments: create(null) }, | ||
oar: create(null), | ||
cmpTemplate: null, | ||
hydrated: Boolean(hydrated), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<x-basic-parent> | ||
<template shadowroot="open"> | ||
<x-basic-child> | ||
<div> | ||
<span> | ||
99 - ssr | ||
</span> | ||
</div> | ||
</x-basic-child> | ||
</template> | ||
</x-basic-parent> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const tagName = 'x-basic-parent'; | ||
export { default } from 'x/basicParent'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template lwc:render-mode="light"> | ||
<div> | ||
<slot lwc:slot-bind={item}>Default slot content</slot> | ||
</div> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Child extends LightningElement { | ||
static renderMode = 'light'; | ||
item = {id: 99, name: 'ssr'} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<template> | ||
<x-basic-child> | ||
<template lwc:slot-data="data"> | ||
<span>{data.id} - {data.name}</span> | ||
</template> | ||
</x-basic-child> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Parent extends LightningElement {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<x-parent-of-child-with-for-each> | ||
<template shadowroot="open"> | ||
<style type="text/css"> | ||
span {background-color: blue;} | ||
</style> | ||
<x-child-with-for-each> | ||
<ul> | ||
<li> | ||
<span> | ||
39 - Audio | ||
</span> | ||
</li> | ||
<li> | ||
<span> | ||
40 - Video | ||
</span> | ||
</li> | ||
</ul> | ||
</x-child-with-for-each> | ||
</template> | ||
</x-parent-of-child-with-for-each> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const tagName = 'x-parent-of-child-with-for-each'; | ||
export { default } from 'x/parentOfChildWithForEach'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<template lwc:render-mode="light"> | ||
<ul> | ||
<template for:each={items} for:item="item"> | ||
<li key={item.id}> | ||
<slot lwc:slot-bind={item}></slot> | ||
</li> | ||
</template> | ||
</ul> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class extends LightningElement { | ||
static renderMode = 'light'; | ||
items = [ | ||
{ id: 39, name: 'Audio' }, | ||
{ id: 40, name: 'Video' }, | ||
]; | ||
} |
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on a separate PR for testing reactivity #3105