Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vatro opened this issue Jun 24, 2022 · 0 comments
Open

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

vatro opened this issue Jun 24, 2022 · 0 comments
Labels

Comments

@vatro
Copy link
Owner

vatro commented Jun 24, 2022

We're already doing it e.g. here:

context = root_component["$$"].context

item.svelthree_comp = new Mesh({
target: dom_target,
props: { geometry: item.mesh.geometry, material: item.mesh.material, name: item.name },
context
})

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:

$: if (mesh && create && !our_parent_shadow_dom_el) set_parent_shadow_dom_el()
function set_parent_shadow_dom_el() {
our_parent_shadow_dom_el = getContext("parent_shadow_dom_el") || scene_shadow_dom_el

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 vatro added the clarify label Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant