svelthree icon indicating copy to clipboard operation
svelthree copied to clipboard

Proper / common way to dynamically change / set component's parent.

Open vatro opened this issue 3 years ago • 0 comments

We're already doing it e.g. here: https://github.com/vatro/svelthree/blob/754a5f115ec0194e026426e2ce50518a573c4079/src/utils/SvelthreeGLTF.ts#L102

https://github.com/vatro/svelthree/blob/754a5f115ec0194e026426e2ce50518a573c4079/src/utils/SvelthreeGLTF.ts#L107-L111

by setting context to parent's context, but is this the proper / common way? Do Svelte people even do it / is it common? 🤔

I've stumbled over this, while asking myself, if / when does it make sense to recreate shadow_dom_el? When would / does our_parent_shadow_dom_el change? see:

https://github.com/vatro/svelthree/blob/754a5f115ec0194e026426e2ce50518a573c4079/src/components/Mesh.svelte#L343-L346

would this make sense?:

$: if (our_parent_shadow_dom_el) {
  create_shadow_dom()
}

Currently it would make no sense, because our_parent_shadow_dom_el is not reactive, it's being set once after initialization via getContext("parent_shadow_dom_el") || scene_shadow_dom_el if our_parent_shadow_dom_el === undefined.

Changing object's parent / adding an object somewhere else / moving it should is a very common task in three.js applications, so it should also be possible with svelthree incl. accordingly updating the shadow DOM representation + good dx, see also: #103

vatro avatar Jun 24 '22 20:06 vatro