Skip to content

Commit

Permalink
updated: use the template key instead of fallback for the slot bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Aug 23, 2024
1 parent 458a7b0 commit 68a5a07
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dom-bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface SimpleBindingData<Scope = any> extends BaseBindingData<Scope> {
}

export interface SlotBindingData<Scope = any> extends BaseBindingData<Scope> {
fallback?: TemplateChunk<Scope>
template?: TemplateChunk<Scope>
}

export interface TagBindingData<Scope = any> extends BaseBindingData<Scope> {
Expand Down
10 changes: 5 additions & 5 deletions src/bindings/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const SlotBinding = {
// name: null,
attributes: [],
// template: null,
// fallback: null

getTemplateScope(scope, parentScope) {
return extendParentScope(this.attributes, scope, parentScope)
Expand All @@ -42,13 +41,14 @@ export const SlotBinding = {
const { parentNode } = this.node
const realParent = getRealParent(scope, parentScope)

// override the template property if the slot needs to be replaced
this.template =
(templateData &&
template(templateData.html, templateData.bindings).createDOM(
parentNode,
)) ||
// use the optional template fallback if provided by the compiler see also https://github.com/riot/riot/issues/3014
this.fallback
// otherwise use the optional template fallback if provided by the compiler see also https://github.com/riot/riot/issues/3014
this.template

if (this.template) {
cleanNode(this.node)
Expand Down Expand Up @@ -107,11 +107,11 @@ function moveSlotInnerContent(slot) {
* @param {AttributeExpressionData[]} attributes - slot attributes
* @returns {Object} Slot binding object
*/
export default function createSlot(node, { name, attributes, fallback }) {
export default function createSlot(node, { name, attributes, template }) {
return {
...SlotBinding,
attributes,
fallback,
template,
node,
name,
}
Expand Down
2 changes: 1 addition & 1 deletion test/bindings/slot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe('slot bindings', () => {
type: bindingTypes.SLOT,
selector: '[expr0]',
name: 'default',
fallback: template('<p>Default</p>'),
template: template('<p>Default</p>'),
},
])

Expand Down

0 comments on commit 68a5a07

Please sign in to comment.