support starting liveview with props

This commit is contained in:
Ian committed 2022-04-24 00:37:46 -04:00
1 parent 608795426a
commit f332ffc5ad
2 files changed
+28 -6

No files matched your search

+12 -3
View File
@@ -9,11 +9,20 @@ 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<T>(&self, ws: warp::ws::WebSocket, app: fn(Scope) -> Element, props: T)
where
T: Send + Sync + 'static
{
connect(ws, self.pool.clone(), app, props)
}
}
pub async fn connect(ws: WebSocket, pool: LocalPoolHandle, app: fn(Scope) -> Element) {
pub async fn connect<T>(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 +35,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();