Skip to content

Commit

Permalink
Merge pull request DioxusLabs#871 from DioxusLabs/jk/liveview-pool
Browse files Browse the repository at this point in the history
Allow liveview to spawn pre-built virtualdoms
  • Loading branch information
jkelleyrtp committed Mar 14, 2023
2 parents 07fc959 + 55446c1 commit 05b3f13
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/liveview/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ impl LiveViewPool {
app: fn(Scope<T>) -> Element,
props: T,
) -> 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(Err(e)) => Err(e),
Err(_) => Err(LiveViewError::SendingFailed),
Expand Down Expand Up @@ -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.
///
/// You might need to transform the error types of the web backend into the LiveView error type.
pub async fn run<T>(
app: Component<T>,
props: T,
ws: impl LiveViewSocket,
) -> Result<(), LiveViewError>
where
T: Send + 'static,
{
pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), LiveViewError> {
#[cfg(all(feature = "hot-reload", debug_assertions))]
let mut hot_reload_rx = {
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
Expand All @@ -112,8 +114,6 @@ where
rx
};

let mut vdom = VirtualDom::new_with_props(app, props);

// todo: use an efficient binary packed format for this
let edits = serde_json::to_string(&vdom.rebuild()).unwrap();

Expand Down

0 comments on commit 05b3f13

Please sign in to comment.