瀏覽代碼

wip: more liveview and webview custom client

Jonathan Kelley 4 年之前
父節點
當前提交
9b560dfedb

+ 3 - 1
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",

+ 0 - 1
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, || "...?");
 

+ 0 - 9
js-host/Cargo.toml

@@ -1,9 +0,0 @@
-[package]
-name = "dixous-jshost"
-version = "0.0.0"
-authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
-edition = "2018"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]

+ 0 - 7
js-host/src/lib.rs

@@ -1,7 +0,0 @@
-#[cfg(test)]
-mod tests {
-    #[test]
-    fn it_works() {
-        assert_eq!(2 + 2, 4);
-    }
-}

+ 1 - 0
packages/cli/Cargo.toml

@@ -28,5 +28,6 @@ rjdebounce = "0.2.1"
 tempfile = "3.2.0"
 
 [[bin]]
+
 path = "src/main.rs"
 name = "dioxus"

+ 0 - 3
packages/livehost/src/lib.rs

@@ -1,3 +0,0 @@
-fn main() {
-    println!("Hello, world!");
-}

+ 0 - 0
packages/livehost/Cargo.toml → packages/liveview/Cargo.toml


+ 0 - 1
packages/livehost/README.md → 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.
 
-

+ 0 - 0
packages/livehost/index.html → packages/liveview/index.html


+ 1 - 0
packages/liveview/src/handlers/h_actix.rs

@@ -0,0 +1 @@
+//! Request handler for actix

+ 1 - 0
packages/liveview/src/handlers/h_rocket.rs

@@ -0,0 +1 @@
+//! Request handler for rocket

+ 1 - 0
packages/liveview/src/handlers/h_tide.rs

@@ -0,0 +1 @@
+//! Request handler for tide

+ 1 - 0
packages/liveview/src/handlers/h_warp.rs

@@ -0,0 +1 @@
+//! Request handler for warp

+ 10 - 0
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;
+}

+ 35 - 0
packages/old/redux/src/lib.rs

@@ -35,3 +35,38 @@ mod tests {
     </Redux>
     */
 }
+
+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<bool> = |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<TypeId, Box<dyn Any>> = HashMap::new();
+}

+ 1 - 1
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 }
         }
     })
 };

+ 12 - 0
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]

+ 4 - 1
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, || {

+ 1 - 0
packages/webview/src/index.html

@@ -0,0 +1 @@
+<!-- this is used to instantiate the module -->

+ 4 - 3
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<T: 'static>(
+pub fn launch<T: Properties + 'static>(
     builder: impl FnOnce(DioxusWebviewBuilder) -> DioxusWebviewBuilder,
     props: T,
     root: FC<T>,
@@ -25,7 +26,7 @@ enum InnerEvent {
     Initiate(Handle<()>),
 }
 
-impl<T: 'static> WebviewRenderer<T> {
+impl<T: Properties + 'static> WebviewRenderer<T> {
     pub fn run(
         root: FC<T>,
         props: T,