From 9b560dfedb988b258f5c564986759cb83730a96c Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Tue, 16 Mar 2021 14:28:54 -0400 Subject: [PATCH] wip: more liveview and webview custom client --- Cargo.toml | 4 ++- README.md | 1 - js-host/Cargo.toml | 9 ------ js-host/src/lib.rs | 7 ----- packages/cli/Cargo.toml | 1 + packages/livehost/src/lib.rs | 3 -- packages/{livehost => liveview}/Cargo.toml | 0 packages/{livehost => liveview}/README.md | 1 - packages/{livehost => liveview}/index.html | 0 packages/liveview/src/handlers/h_actix.rs | 1 + packages/liveview/src/handlers/h_rocket.rs | 1 + packages/liveview/src/handlers/h_tide.rs | 1 + packages/liveview/src/handlers/h_warp.rs | 1 + packages/liveview/src/lib.rs | 10 +++++++ packages/old/redux/src/lib.rs | 35 ++++++++++++++++++++++ packages/web/examples/infer.rs | 2 +- packages/webview/Cargo.toml | 12 ++++++++ packages/webview/client/src/main.rs | 5 +++- packages/webview/src/index.html | 1 + packages/webview/src/lib.rs | 7 +++-- 20 files changed, 75 insertions(+), 27 deletions(-) delete mode 100644 js-host/Cargo.toml delete mode 100644 js-host/src/lib.rs delete mode 100644 packages/livehost/src/lib.rs rename packages/{livehost => liveview}/Cargo.toml (100%) rename packages/{livehost => liveview}/README.md (99%) rename packages/{livehost => liveview}/index.html (100%) create mode 100644 packages/liveview/src/handlers/h_actix.rs create mode 100644 packages/liveview/src/handlers/h_rocket.rs create mode 100644 packages/liveview/src/handlers/h_tide.rs create mode 100644 packages/liveview/src/handlers/h_warp.rs create mode 100644 packages/liveview/src/lib.rs create mode 100644 packages/webview/src/index.html diff --git a/Cargo.toml b/Cargo.toml index 0c7cdfa86..07fccc61a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,9 @@ members = [ "packages/core-macro", "packages/core", "packages/web", - "packages/webview/client" + "packages/webview/client", + "packages/webview", + "packages/liveview", # "packages/router", # "packages/ssr", # "packages/webview", diff --git a/README.md b/README.md index a746a1c7a..0628a486b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ Dioxus is a portable, performant, and ergonomic framework for building cross-pla ```rust -#[fc] static Example: FC<()> = |ctx, props| { let (selection, set_selection) = use_state(&ctx, || "...?"); diff --git a/js-host/Cargo.toml b/js-host/Cargo.toml deleted file mode 100644 index 14aa743f1..000000000 --- a/js-host/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "dixous-jshost" -version = "0.0.0" -authors = ["Jonathan Kelley "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] \ No newline at end of file diff --git a/js-host/src/lib.rs b/js-host/src/lib.rs deleted file mode 100644 index 31e1bb209..000000000 --- a/js-host/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index 500950fe0..2b60832ce 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -28,5 +28,6 @@ rjdebounce = "0.2.1" tempfile = "3.2.0" [[bin]] + path = "src/main.rs" name = "dioxus" diff --git a/packages/livehost/src/lib.rs b/packages/livehost/src/lib.rs deleted file mode 100644 index e7a11a969..000000000 --- a/packages/livehost/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/packages/livehost/Cargo.toml b/packages/liveview/Cargo.toml similarity index 100% rename from packages/livehost/Cargo.toml rename to packages/liveview/Cargo.toml diff --git a/packages/livehost/README.md b/packages/liveview/README.md similarity index 99% rename from packages/livehost/README.md rename to packages/liveview/README.md index c9b17c12b..f1c4f9b86 100644 --- a/packages/livehost/README.md +++ b/packages/liveview/README.md @@ -11,4 +11,3 @@ This comes in the form of two approaches: Tight coupling is basically an implmentation of loose coupling where **all** events move through the backend connection. This coupling option has higher latency but is very simple to deploy. We use this approach for dioxus-webview where latency is minimal (hosted locally) and we want builds to be simple - no need to manually bundle a custom frontend because everything is server rendered. - diff --git a/packages/livehost/index.html b/packages/liveview/index.html similarity index 100% rename from packages/livehost/index.html rename to packages/liveview/index.html diff --git a/packages/liveview/src/handlers/h_actix.rs b/packages/liveview/src/handlers/h_actix.rs new file mode 100644 index 000000000..7f285a019 --- /dev/null +++ b/packages/liveview/src/handlers/h_actix.rs @@ -0,0 +1 @@ +//! Request handler for actix diff --git a/packages/liveview/src/handlers/h_rocket.rs b/packages/liveview/src/handlers/h_rocket.rs new file mode 100644 index 000000000..b010d8767 --- /dev/null +++ b/packages/liveview/src/handlers/h_rocket.rs @@ -0,0 +1 @@ +//! Request handler for rocket diff --git a/packages/liveview/src/handlers/h_tide.rs b/packages/liveview/src/handlers/h_tide.rs new file mode 100644 index 000000000..41a06a713 --- /dev/null +++ b/packages/liveview/src/handlers/h_tide.rs @@ -0,0 +1 @@ +//! Request handler for tide diff --git a/packages/liveview/src/handlers/h_warp.rs b/packages/liveview/src/handlers/h_warp.rs new file mode 100644 index 000000000..692749dd6 --- /dev/null +++ b/packages/liveview/src/handlers/h_warp.rs @@ -0,0 +1 @@ +//! Request handler for warp diff --git a/packages/liveview/src/lib.rs b/packages/liveview/src/lib.rs new file mode 100644 index 000000000..db5bb1352 --- /dev/null +++ b/packages/liveview/src/lib.rs @@ -0,0 +1,10 @@ +mod handlers { + + pub mod h_actix; + + pub mod h_rocket; + + pub mod h_tide; + + pub mod h_warp; +} diff --git a/packages/old/redux/src/lib.rs b/packages/old/redux/src/lib.rs index ba45112fa..7c93ab25e 100644 --- a/packages/old/redux/src/lib.rs +++ b/packages/old/redux/src/lib.rs @@ -35,3 +35,38 @@ mod tests { */ } + +struct Context { + data: String, + logged_in: bool, +} + +// "static" selectors automatically get memoized +static SelectUserName: Selector<&str> = |root: Context| root.data.as_str(); +static SelectUserName: Selector = |root: Context| root.data.logged_in; + +fn main() { + /* + use_context is very unsafe! It essentially exposes your data in an unsafecell where &mut T and &T can exist at the same time. It's up to *you* the library implmenetor to make this safe. + + We provide a redux-style system and a recoil-style system that are both saf + + */ + + // connect itsy bits of state together + let context = use_create_context( + ctx, + ContextBuilder::new() + .with_root(|| Context {}) + .with_root(|| Context {}) + .with_root(|| Context {}) + .with_root(|| Context {}) + .with_root(|| Context {}) + .with_root(|| Context {}) + .with_root(|| Context {}) + .with_root(|| Context {}) + .build(), + ); + + let g: HashMap> = HashMap::new(); +} diff --git a/packages/web/examples/infer.rs b/packages/web/examples/infer.rs index 00f3e72cc..06140f6ef 100644 --- a/packages/web/examples/infer.rs +++ b/packages/web/examples/infer.rs @@ -38,7 +38,7 @@ static Example: FC<()> = |ctx, _props| { id: "json" "{event}" } - // Example2 { name: "{event}".to_string() } + Example2 { name: event } } }) }; diff --git a/packages/webview/Cargo.toml b/packages/webview/Cargo.toml index a3563da00..d428bb9e2 100644 --- a/packages/webview/Cargo.toml +++ b/packages/webview/Cargo.toml @@ -21,5 +21,17 @@ thiserror = "1.0.23" log = "0.4.13" fern = { version = "0.6.0", features = ["colored"] } +# thiserror = "1.0.23" +# log = "0.4.13" +# fern = { version = "0.6.0", features = ["colored"] } +# wasm-bindgen-cli-support = "0.2.71" +# anyhow = "1.0.38" +# argh = "0.1.4" +# serde = "1.0.120" +# serde_json = "1.0.61" +# async-std = { version = "1.9.0", features = ["attributes"] } +tide = "0.15.0" +tide-websockets = "0.3.0" + [build-dependencies] diff --git a/packages/webview/client/src/main.rs b/packages/webview/client/src/main.rs index 7a96b2aa0..9230c4c41 100644 --- a/packages/webview/client/src/main.rs +++ b/packages/webview/client/src/main.rs @@ -14,7 +14,10 @@ struct ServerRendered { name7: String, } -fn main() { +fn main() {} + +#[cfg(old)] +fn blah() { // connect to the host server let server_rendered = use_server_rendered((111111, 11111, 11), SERVER_RENDERED_KEY, || { diff --git a/packages/webview/src/index.html b/packages/webview/src/index.html new file mode 100644 index 000000000..9beef451b --- /dev/null +++ b/packages/webview/src/index.html @@ -0,0 +1 @@ + diff --git a/packages/webview/src/lib.rs b/packages/webview/src/lib.rs index fe96d9e0f..61877c36e 100644 --- a/packages/webview/src/lib.rs +++ b/packages/webview/src/lib.rs @@ -2,12 +2,13 @@ use std::sync::mpsc::channel; use std::sync::Arc; use dioxus_core::prelude::*; +use dioxus_core::virtual_dom::VirtualDom; use web_view::Handle; use web_view::{WVResult, WebView, WebViewBuilder}; -static HTML_CONTENT: &'static str = include_str!("./index.html"); +static HTML_CONTENT: &'static str = include_str!("./../../liveview/index.html"); -pub fn launch( +pub fn launch( builder: impl FnOnce(DioxusWebviewBuilder) -> DioxusWebviewBuilder, props: T, root: FC, @@ -25,7 +26,7 @@ enum InnerEvent { Initiate(Handle<()>), } -impl WebviewRenderer { +impl WebviewRenderer { pub fn run( root: FC, props: T,