Slot
The Duck way of implementing component slots. Slots allow you to render arbitrary content in a component.
Demo
live demo | files
Recipe
In Practice
Copy-paste the highlighted sections in the first code snippet into the component with the slot.
Then, pass a DOM element into the component as
containerComponent.data.slot
and then call containerComponent.update()
.
Walkthrough
Slots in Duck are actually pretty simple. A slot is just a reference to a DOM element.
In
update()
you simply check if data.slot
is different than before, remove the old one, and append the new one.
If you want to use a component as a slot, you simply pass component.elem
.
Notes
Feel free to use as many slots as you want. Just use a different
data
property name per slot. For example, you can do data.slot1
and data.slot2
(very original).