diff --git a/packages/liveview/src/adapters/axum_adapter.rs b/packages/liveview/src/adapters/axum_adapter.rs index d85b6da68..4122950bc 100644 --- a/packages/liveview/src/adapters/axum_adapter.rs +++ b/packages/liveview/src/adapters/axum_adapter.rs @@ -9,21 +9,33 @@ use tokio::sync::mpsc; use tokio_stream::wrappers::UnboundedReceiverStream; use tokio_util::task::LocalPoolHandle; -#[cfg(feature = "axum")] impl crate::Liveview { pub async fn upgrade(&self, ws: WebSocket, app: fn(Scope) -> Element) { - connect(ws, self.pool.clone(), app).await; + connect(ws, self.pool.clone(), app, ()).await; + } + pub async fn upgrade_with_props(&self, ws: WebSocket, app: fn(Scope) -> Element, props: T) + where + T: Send + Sync + 'static, + { + connect(ws, self.pool.clone(), app, props).await; } } -pub async fn connect(socket: WebSocket, pool: LocalPoolHandle, app: fn(Scope) -> Element) { +pub async fn connect( + socket: WebSocket, + pool: LocalPoolHandle, + app: fn(Scope) -> Element, + props: T, +) where + T: Send + Sync + 'static, +{ let (mut user_ws_tx, mut user_ws_rx) = socket.split(); let (event_tx, event_rx) = mpsc::unbounded_channel(); let (edits_tx, edits_rx) = mpsc::unbounded_channel(); let mut edits_rx = UnboundedReceiverStream::new(edits_rx); let mut event_rx = UnboundedReceiverStream::new(event_rx); let vdom_fut = pool.clone().spawn_pinned(move || async move { - let mut vdom = VirtualDom::new(app); + let mut vdom = VirtualDom::new_with_props(app, props); let edits = vdom.rebuild(); let serialized = serde_json::to_string(&edits.edits).unwrap(); edits_tx.send(serialized).unwrap(); diff --git a/packages/liveview/src/adapters/warp_adapter.rs b/packages/liveview/src/adapters/warp_adapter.rs index 5bdcf671f..f3cf3914b 100644 --- a/packages/liveview/src/adapters/warp_adapter.rs +++ b/packages/liveview/src/adapters/warp_adapter.rs @@ -6,14 +6,30 @@ use tokio_stream::wrappers::UnboundedReceiverStream; use tokio_util::task::LocalPoolHandle; use warp::ws::{Message, WebSocket}; -#[cfg(feature = "warp")] impl crate::Liveview { pub async fn upgrade(&self, ws: warp::ws::WebSocket, app: fn(Scope) -> Element) { - connect(ws, self.pool.clone(), app).await; + connect(ws, self.pool.clone(), app, ()).await; + } + pub async fn upgrade_with_props( + &self, + ws: warp::ws::WebSocket, + app: fn(Scope) -> Element, + props: T, + ) where + T: Send + Sync + 'static, + { + connect(ws, self.pool.clone(), app, props).await; } } -pub async fn connect(ws: WebSocket, pool: LocalPoolHandle, app: fn(Scope) -> Element) { +pub async fn connect( + ws: WebSocket, + pool: LocalPoolHandle, + app: fn(Scope) -> Element, + props: T, +) where + T: Send + Sync + 'static, +{ // Use a counter to assign a new unique ID for this user. // Split the socket into a sender and receive of messages. @@ -26,7 +42,7 @@ pub async fn connect(ws: WebSocket, pool: LocalPoolHandle, app: fn(Scope) -> Ele let mut event_rx = UnboundedReceiverStream::new(event_rx); let vdom_fut = pool.spawn_pinned(move || async move { - let mut vdom = VirtualDom::new(app); + let mut vdom = VirtualDom::new_with_props(app, props); let edits = vdom.rebuild();