You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there is no way to unmount a Yew app after it has been started, which is useful/necessary if you want to use Yew to create standalone widget/components in a larger non-Yew project.
Our use case:
We are currently creating a Yew app that we want to distribute to our partners as a widget/plugin to be used on their own website.
Our current approach is to expose an initialization JS function that takes an html element which then mounts the yew app with App::mount_with_props, and HOPE that they don't call the initialization function twice. However we have found that this is pretty hard to control with single page websites, e.g. React website, especially when we don't control the surroundings of our Yew app. For this reason we would like to introduce a way to unmount/destroy an Yew app cleanly so we can expose the same functionality in our API.
Our proposal is to use underutilized yew::app::App struct by:
Change all the mount_* functions from mount(self) -> ComponentLink<..> to mount(self) -> self
Add a method get_component_link(&self) -> ComponentLink<..> on App, to compensate for the changes in the function signatures in point 1.
Add a method destroy(self) on App that schedules a destruction of the inner scope of the app.
By doing the above we effectively change the App struct from being a "initialize and consume struct" to be a real handle to a specific instantiation of a Yew app.
We have a working example here https://github.com/Skybox-Technologies/yew/tree/destroy_app which we have tested with our mentioned app, the repo however doesn't yet include any standalone tests for the new functionality (I'll add them soon).
Edit: Updated the link to point to the right branch.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently there is no way to unmount a Yew app after it has been started, which is useful/necessary if you want to use Yew to create standalone widget/components in a larger non-Yew project.
Our use case:
We are currently creating a Yew app that we want to distribute to our partners as a widget/plugin to be used on their own website.
Our current approach is to expose an initialization JS function that takes an html element which then mounts the yew app with App::mount_with_props, and HOPE that they don't call the initialization function twice. However we have found that this is pretty hard to control with single page websites, e.g. React website, especially when we don't control the surroundings of our Yew app. For this reason we would like to introduce a way to unmount/destroy an Yew app cleanly so we can expose the same functionality in our API.
Our proposal is to use underutilized yew::app::App struct by:
mount(self) -> ComponentLink<..>
tomount(self) -> self
get_component_link(&self) -> ComponentLink<..>
on App, to compensate for the changes in the function signatures in point 1.destroy(self)
on App that schedules a destruction of the inner scope of the app.By doing the above we effectively change the App struct from being a "initialize and consume struct" to be a real handle to a specific instantiation of a Yew app.
We have a working example here https://github.com/Skybox-Technologies/yew/tree/destroy_app which we have tested with our mentioned app, the repo however doesn't yet include any standalone tests for the new functionality (I'll add them soon).
Edit: Updated the link to point to the right branch.
Beta Was this translation helpful? Give feedback.
All reactions