Merge pull request #871 from DioxusLabs/jk/liveview-pool
Allow liveview to spawn pre-built virtualdoms
This commit is contained in:
1 file changed
+11
-11
@@ -37,7 +37,16 @@ impl LiveViewPool {
|
|||||||
app: fn(Scope<T>) -> Element,
|
app: fn(Scope<T>) -> Element,
|
||||||
props: T,
|
props: T,
|
||||||
) -> Result<(), LiveViewError> {
|
) -> Result<(), LiveViewError> {
|
||||||
match self.pool.spawn_pinned(move || run(app, props, ws)).await {
|
self.launch_virtualdom(ws, move || VirtualDom::new_with_props(app, props))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn launch_virtualdom<F: FnOnce() -> VirtualDom + Send + 'static>(
|
||||||
|
&self,
|
||||||
|
ws: impl LiveViewSocket,
|
||||||
|
make_app: F,
|
||||||
|
) -> Result<(), LiveViewError> {
|
||||||
|
match self.pool.spawn_pinned(move || run(make_app(), ws)).await {
|
||||||
Ok(Ok(_)) => Ok(()),
|
Ok(Ok(_)) => Ok(()),
|
||||||
Ok(Err(e)) => Err(e),
|
Ok(Err(e)) => Err(e),
|
||||||
Err(_) => Err(LiveViewError::SendingFailed),
|
Err(_) => Err(LiveViewError::SendingFailed),
|
||||||
@@ -95,14 +104,7 @@ impl<S> LiveViewSocket for S where
|
|||||||
/// As long as your framework can provide a Sink and Stream of Strings, you can use this function.
|
/// As long as your framework can provide a Sink and Stream of Strings, you can use this function.
|
||||||
///
|
///
|
||||||
/// You might need to transform the error types of the web backend into the LiveView error type.
|
/// You might need to transform the error types of the web backend into the LiveView error type.
|
||||||
pub async fn run<T>(
|
pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), LiveViewError> {
|
||||||
app: Component<T>,
|
|
||||||
props: T,
|
|
||||||
ws: impl LiveViewSocket,
|
|
||||||
) -> Result<(), LiveViewError>
|
|
||||||
where
|
|
||||||
T: Send + 'static,
|
|
||||||
{
|
|
||||||
#[cfg(all(feature = "hot-reload", debug_assertions))]
|
#[cfg(all(feature = "hot-reload", debug_assertions))]
|
||||||
let mut hot_reload_rx = {
|
let mut hot_reload_rx = {
|
||||||
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
|
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
@@ -112,8 +114,6 @@ where
|
|||||||
rx
|
rx
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut vdom = VirtualDom::new_with_props(app, props);
|
|
||||||
|
|
||||||
// todo: use an efficient binary packed format for this
|
// todo: use an efficient binary packed format for this
|
||||||
let edits = serde_json::to_string(&vdom.rebuild()).unwrap();
|
let edits = serde_json::to_string(&vdom.rebuild()).unwrap();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user