I have a virtual scrollbar, In svelte4 I can programmatically set a svelte component to the default value of the slot.
How can I achieve the same effect in Svelte 5?
@2-/svelte_slot/index.js
import { detach, mount_component, noop } from "svelte/internal"
// https://github.com/sveltejs/svelte/issues/2588#issuecomment-1134612872
export default (svelte_component) => () => {
let c
return {
c: noop,
// mount
m: (target, anchor) => {
mount_component(
(c = new svelte_component({
target,
})),
target,
anchor,
null,
)
},
// destroy
d: (detaching) => {
if (detaching) {
detach(c)
}
},
l: noop,
}
}
scrollbar.js
import slot from "@2-/svelte_slot"
import Mfs from "@8p/topbar/Mfs.svelte"
export default (svelte) => {
return class extends Mfs {
constructor(opts) {
let { props } = opts
if (!props) {
opts.props = props = {}
}
props.$$scope = {}
props.$$slots = { default: [slot(svelte)] }
super(opts)
}
}
}