yew icon indicating copy to clipboard operation
yew copied to clipboard

Third-party components embedding

Open therustmonk opened this issue 8 years ago • 6 comments

According to #83 we need a capability to embed third-party components which lives in own lifecycle, like Ace.

therustmonk avatar Jan 07 '18 09:01 therustmonk

I'm looking forward to this. My use case is: I'm writing a game with the unrust webgl engine, and want to have a HUD GUI overlay based on html with yew (also a chat text field etc.) so I need two way communication between the yew app and the wasm game.. What would be the best way to do this? Using wasm imported/exported functions for rpc?

Boscop avatar May 16 '18 14:05 Boscop

Missing label:

  • feature

samuelvanderwaal avatar Jan 31 '20 04:01 samuelvanderwaal

@hamza1311 , if this is not been solved, can you please assign this ticket to me? Loosely related to #135

tieje avatar Feb 19 '23 22:02 tieje

Don't portals solve this? I'm not sure what the solution here is. Do you have anything in mind, @tieje?

CC: @WorldSEnder

ranile avatar Feb 19 '23 22:02 ranile

Don't portals solve this? I'm not sure what the solution here is. Do you have anything in mind, @tieje?

CC: @WorldSEnder

I don't know. Sorry, but I am still yet a learner.

tieje avatar Feb 21 '23 00:02 tieje

Portals can get you there, to some degree. You could for example render something akin to

// Create your third-party component somehow, probably by calling to JS
// Should not be in the view function directly, but in use_state or the component's create
let third_party_element: web_sys::Element = todo!();
// Now, in the view function you can use a portal to let yew handle the children of that element
// These could be for example slotted
let portal_to_children = yew::html::create_portal(html! {
    <>
        <p slot="some-slot">{"I will be rendered as a child of third_party_element"}</p>
        <p slot="some-other-slot">{"E.g. 'slot' can be used with web components"}</p>
    </>
}, third_party_element.clone());
// Render both the original element, and the portal
html! {
<> 
    {portal_to_children}
    {VDom::VRef(third_party_element.into())}
</>
}

Note: I haven't thought about event propagation/bubbling with the above, but I think it should work fine.

WorldSEnder avatar Mar 20 '23 05:03 WorldSEnder