@yatoi/slots
v0.2.0
Published
Framework-neutral slot contract for @yatoi/kernel: the Slots interface and slot().
Downloads
339
Maintainers
Readme
@yatoi/slots
The framework-neutral slot contract for declaring typed contribution points on @yatoi/kernel.
Install
npm i @yatoi/kernel @yatoi/slotsimport { createKernel, definePlugin } from '@yatoi/kernel'
import { slot } from '@yatoi/slots'
declare module '@yatoi/slots' {
interface Slots { 'task.badge': { taskId: string } }
}
const badges = definePlugin({ name: 'badges', setup(scope) {
scope.contribute(slot('task.badge'), 'badge renderer')
} })
const kernel = createKernel()
kernel.load(badges)
console.log(kernel.list(slot('task.badge')).length)Rules
- The host declares the
Slotsinterface once in a contract module imported by host and plugins. - Import
slotand the host contract; never constructslot:*string keys at call sites. - Keep
@yatoi/slotsframework-neutral; rendering belongs in@yatoi/react/slotsor@yatoi/vue/slots. - Never mutate the kernel during render; contributions belong in plugin setup.
Specification · Guide · Pitfalls · React example
More
Every slot is an ordinary kernel collection. Contributions therefore disappear automatically when their owning plugin unloads, without a separate unregister operation.
MIT
