Merge branch 'master' of https://github.com/DioxusLabs/dioxus into rusty-events
Conflicts: packages/html/src/events.rs packages/tui/src/hooks.rs
This commit is contained in:
commit
f3fcec2bdf
87 files changed
+6230
-868
No files matched your search
@@ -1,36 +1,31 @@
|
||||
use axum::{
|
||||
extract::ws::WebSocketUpgrade, response::Html, response::IntoResponse, routing::get, Extension,
|
||||
Router,
|
||||
};
|
||||
#![cfg(feature = "axum")]
|
||||
|
||||
use axum::{extract::ws::WebSocketUpgrade, response::Html, routing::get, Router};
|
||||
use dioxus_core::{Element, LazyNodes, Scope};
|
||||
use dioxus_liveview::Liveview;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
#[cfg(feature = "axum")]
|
||||
{
|
||||
pretty_env_logger::init();
|
||||
pretty_env_logger::init();
|
||||
|
||||
let addr: std::net::SocketAddr = ([127, 0, 0, 1], 3030).into();
|
||||
let addr: std::net::SocketAddr = ([127, 0, 0, 1], 3030).into();
|
||||
|
||||
let view = dioxus_liveview::new(addr);
|
||||
let body = view.body("<title>Dioxus Liveview</title>");
|
||||
let view = dioxus_liveview::new(addr);
|
||||
let body = view.body("<title>Dioxus Liveview</title>");
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(move || async { Html(body) }))
|
||||
.route(
|
||||
"/app",
|
||||
get(move |ws: WebSocketUpgrade| async move {
|
||||
ws.on_upgrade(move |socket| async move {
|
||||
view.upgrade(socket, app).await;
|
||||
})
|
||||
}),
|
||||
);
|
||||
axum::Server::bind(&addr.to_string().parse().unwrap())
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
let app = Router::new()
|
||||
.route("/", get(move || async { Html(body) }))
|
||||
.route(
|
||||
"/app",
|
||||
get(move |ws: WebSocketUpgrade| async move {
|
||||
ws.on_upgrade(move |socket| async move {
|
||||
view.upgrade_axum(socket, app).await;
|
||||
})
|
||||
}),
|
||||
);
|
||||
axum::Server::bind(&addr.to_string().parse().unwrap())
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![cfg(feature = "warp")]
|
||||
|
||||
use dioxus_core::{Element, LazyNodes, Scope};
|
||||
use dioxus_liveview as liveview;
|
||||
use warp::ws::Ws;
|
||||
@@ -5,28 +7,25 @@ use warp::Filter;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
#[cfg(feature = "warp")]
|
||||
{
|
||||
pretty_env_logger::init();
|
||||
pretty_env_logger::init();
|
||||
|
||||
let addr = ([127, 0, 0, 1], 3030);
|
||||
let addr = ([127, 0, 0, 1], 3030);
|
||||
|
||||
// todo: compactify this routing under one liveview::app method
|
||||
let view = liveview::new(addr);
|
||||
let body = view.body("<title>Dioxus LiveView</title>");
|
||||
// todo: compactify this routing under one liveview::app method
|
||||
let view = liveview::new(addr);
|
||||
let body = view.body("<title>Dioxus LiveView</title>");
|
||||
|
||||
let routes = warp::path::end()
|
||||
.map(move || warp::reply::html(body.clone()))
|
||||
.or(warp::path("app")
|
||||
.and(warp::ws())
|
||||
.and(warp::any().map(move || view.clone()))
|
||||
.map(|ws: Ws, view: liveview::Liveview| {
|
||||
ws.on_upgrade(|socket| async move {
|
||||
view.upgrade(socket, app).await;
|
||||
})
|
||||
}));
|
||||
warp::serve(routes).run(addr).await;
|
||||
}
|
||||
let routes = warp::path::end()
|
||||
.map(move || warp::reply::html(body.clone()))
|
||||
.or(warp::path("app")
|
||||
.and(warp::ws())
|
||||
.and(warp::any().map(move || view.clone()))
|
||||
.map(|ws: Ws, view: liveview::Liveview| {
|
||||
ws.on_upgrade(|socket| async move {
|
||||
view.upgrade_warp(socket, app).await;
|
||||
})
|
||||
}));
|
||||
warp::serve(routes).run(addr).await;
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{events, Liveview};
|
||||
use crate::events;
|
||||
use axum::extract::ws::{Message, WebSocket};
|
||||
use dioxus_core::prelude::*;
|
||||
use futures_util::{
|
||||
@@ -10,11 +10,16 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
use tokio_util::task::LocalPoolHandle;
|
||||
|
||||
impl crate::Liveview {
|
||||
pub async fn upgrade(&self, ws: WebSocket, app: fn(Scope) -> Element) {
|
||||
pub async fn upgrade_axum(&self, ws: WebSocket, app: fn(Scope) -> Element) {
|
||||
connect(ws, self.pool.clone(), app, ()).await;
|
||||
}
|
||||
pub async fn upgrade_with_props<T>(&self, ws: WebSocket, app: fn(Scope<T>) -> Element, props: T)
|
||||
where
|
||||
|
||||
pub async fn upgrade_axum_with_props<T>(
|
||||
&self,
|
||||
ws: WebSocket,
|
||||
app: fn(Scope<T>) -> Element,
|
||||
props: T,
|
||||
) where
|
||||
T: Send + Sync + 'static,
|
||||
{
|
||||
connect(ws, self.pool.clone(), app, props).await;
|
||||
|
||||
@@ -7,10 +7,10 @@ use tokio_util::task::LocalPoolHandle;
|
||||
use warp::ws::{Message, WebSocket};
|
||||
|
||||
impl crate::Liveview {
|
||||
pub async fn upgrade(&self, ws: warp::ws::WebSocket, app: fn(Scope) -> Element) {
|
||||
pub async fn upgrade_warp(&self, ws: warp::ws::WebSocket, app: fn(Scope) -> Element) {
|
||||
connect(ws, self.pool.clone(), app, ()).await;
|
||||
}
|
||||
pub async fn upgrade_with_props<T>(
|
||||
pub async fn upgrade_warp_with_props<T>(
|
||||
&self,
|
||||
ws: warp::ws::WebSocket,
|
||||
app: fn(Scope<T>) -> Element,
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
|
||||
use dioxus_core::{ElementId, EventPriority, UserEvent};
|
||||
use dioxus_html::event_bubbles;
|
||||
use dioxus_html::on::*;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
@@ -46,6 +47,7 @@ pub fn trigger_from_serialized(val: serde_json::Value) -> UserEvent {
|
||||
scope_id: None,
|
||||
element: mounted_dom_id,
|
||||
data: event,
|
||||
bubbles: event_bubbles(name),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,21 +7,10 @@ pub mod adapters {
|
||||
|
||||
#[cfg(feature = "axum")]
|
||||
pub mod axum_adapter;
|
||||
|
||||
#[cfg(feature = "actix")]
|
||||
pub mod actix_adapter;
|
||||
}
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
#[cfg(feature = "warp")]
|
||||
pub use adapters::warp_adapter::connect;
|
||||
|
||||
#[cfg(feature = "axum")]
|
||||
pub use adapters::axum_adapter::connect;
|
||||
|
||||
#[cfg(feature = "actix")]
|
||||
pub use adapters::actix_adapter::connect;
|
||||
use tokio_util::task::LocalPoolHandle;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
Reference in new issue
Block a user