wip: more liveview and webview custom client

This commit is contained in:
Jonathan Kelley 2021-03-16 14:28:54 -04:00
parent 7856f2b153
commit 9b560dfedb
20 changed files with 75 additions and 27 deletions

View file

@ -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",

View file

@ -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, || "...?");

View file

@ -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]

View file

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

View file

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

View file

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

View file

@ -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.

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,10 @@
mod handlers {
pub mod h_actix;
pub mod h_rocket;
pub mod h_tide;
pub mod h_warp;
}

View file

@ -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();
}

View file

@ -38,7 +38,7 @@ static Example: FC<()> = |ctx, _props| {
id: "json"
"{event}"
}
// Example2 { name: "{event}".to_string() }
Example2 { name: event }
}
})
};

View file

@ -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]

View file

@ -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, || {

View file

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

View file

@ -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,