mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 04:33:06 +00:00
wip: more liveview and webview custom client
This commit is contained in:
parent
7856f2b153
commit
9b560dfedb
20 changed files with 75 additions and 27 deletions
|
@ -5,7 +5,9 @@ members = [
|
||||||
"packages/core-macro",
|
"packages/core-macro",
|
||||||
"packages/core",
|
"packages/core",
|
||||||
"packages/web",
|
"packages/web",
|
||||||
"packages/webview/client"
|
"packages/webview/client",
|
||||||
|
"packages/webview",
|
||||||
|
"packages/liveview",
|
||||||
# "packages/router",
|
# "packages/router",
|
||||||
# "packages/ssr",
|
# "packages/ssr",
|
||||||
# "packages/webview",
|
# "packages/webview",
|
||||||
|
|
|
@ -11,7 +11,6 @@ Dioxus is a portable, performant, and ergonomic framework for building cross-pla
|
||||||
|
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#[fc]
|
|
||||||
static Example: FC<()> = |ctx, props| {
|
static Example: FC<()> = |ctx, props| {
|
||||||
let (selection, set_selection) = use_state(&ctx, || "...?");
|
let (selection, set_selection) = use_state(&ctx, || "...?");
|
||||||
|
|
||||||
|
|
|
@ -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]
|
|
|
@ -1,7 +0,0 @@
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
assert_eq!(2 + 2, 4);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,5 +28,6 @@ rjdebounce = "0.2.1"
|
||||||
tempfile = "3.2.0"
|
tempfile = "3.2.0"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
name = "dioxus"
|
name = "dioxus"
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
fn main() {
|
|
||||||
println!("Hello, world!");
|
|
||||||
}
|
|
|
@ -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.
|
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.
|
||||||
|
|
||||||
|
|
1
packages/liveview/src/handlers/h_actix.rs
Normal file
1
packages/liveview/src/handlers/h_actix.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
//! Request handler for actix
|
1
packages/liveview/src/handlers/h_rocket.rs
Normal file
1
packages/liveview/src/handlers/h_rocket.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
//! Request handler for rocket
|
1
packages/liveview/src/handlers/h_tide.rs
Normal file
1
packages/liveview/src/handlers/h_tide.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
//! Request handler for tide
|
1
packages/liveview/src/handlers/h_warp.rs
Normal file
1
packages/liveview/src/handlers/h_warp.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
//! Request handler for warp
|
10
packages/liveview/src/lib.rs
Normal file
10
packages/liveview/src/lib.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
mod handlers {
|
||||||
|
|
||||||
|
pub mod h_actix;
|
||||||
|
|
||||||
|
pub mod h_rocket;
|
||||||
|
|
||||||
|
pub mod h_tide;
|
||||||
|
|
||||||
|
pub mod h_warp;
|
||||||
|
}
|
|
@ -35,3 +35,38 @@ mod tests {
|
||||||
</Redux>
|
</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();
|
||||||
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ static Example: FC<()> = |ctx, _props| {
|
||||||
id: "json"
|
id: "json"
|
||||||
"{event}"
|
"{event}"
|
||||||
}
|
}
|
||||||
// Example2 { name: "{event}".to_string() }
|
Example2 { name: event }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,5 +21,17 @@ thiserror = "1.0.23"
|
||||||
log = "0.4.13"
|
log = "0.4.13"
|
||||||
fern = { version = "0.6.0", features = ["colored"] }
|
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]
|
[build-dependencies]
|
||||||
|
|
|
@ -14,7 +14,10 @@ struct ServerRendered {
|
||||||
name7: String,
|
name7: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {}
|
||||||
|
|
||||||
|
#[cfg(old)]
|
||||||
|
fn blah() {
|
||||||
// connect to the host server
|
// connect to the host server
|
||||||
|
|
||||||
let server_rendered = use_server_rendered((111111, 11111, 11), SERVER_RENDERED_KEY, || {
|
let server_rendered = use_server_rendered((111111, 11111, 11), SERVER_RENDERED_KEY, || {
|
||||||
|
|
1
packages/webview/src/index.html
Normal file
1
packages/webview/src/index.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<!-- this is used to instantiate the module -->
|
|
@ -2,12 +2,13 @@ use std::sync::mpsc::channel;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use dioxus_core::prelude::*;
|
use dioxus_core::prelude::*;
|
||||||
|
use dioxus_core::virtual_dom::VirtualDom;
|
||||||
use web_view::Handle;
|
use web_view::Handle;
|
||||||
use web_view::{WVResult, WebView, WebViewBuilder};
|
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,
|
builder: impl FnOnce(DioxusWebviewBuilder) -> DioxusWebviewBuilder,
|
||||||
props: T,
|
props: T,
|
||||||
root: FC<T>,
|
root: FC<T>,
|
||||||
|
@ -25,7 +26,7 @@ enum InnerEvent {
|
||||||
Initiate(Handle<()>),
|
Initiate(Handle<()>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: 'static> WebviewRenderer<T> {
|
impl<T: Properties + 'static> WebviewRenderer<T> {
|
||||||
pub fn run(
|
pub fn run(
|
||||||
root: FC<T>,
|
root: FC<T>,
|
||||||
props: T,
|
props: T,
|
||||||
|
|
Loading…
Reference in a new issue