wip: making progress on diffing and hydration
This commit is contained in:
1 parent
e5c88fe3a4
commit
49856ccd68
34 files changed
+1023
-750
No files matched your search
@@ -12,8 +12,10 @@ use std::fs::{self, DirEntry};
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
dioxus::desktop::launch(App, |c| {
|
||||
c.with_resizable(false)
|
||||
.with_inner_size(LogicalSize::new(800.0, 400.0))
|
||||
c.with_window(|w| {
|
||||
w.with_resizable(false)
|
||||
.with_inner_size(LogicalSize::new(800.0, 400.0))
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//! Example: realworld usage of hydration
|
||||
//! ------------------------------------
|
||||
//!
|
||||
//! This example shows how to pre-render a page using dioxus SSR and then how to rehydrate it on the client side.
|
||||
//!
|
||||
//! To accomplish hydration on the web, you'll want to set up a slightly more sophisticated build & bundle strategy. In
|
||||
//! the official docs, we have a guide for using DioxusStudio as a build tool with pre-rendering and hydration.
|
||||
//!
|
||||
//! In this example, we pre-render the page to HTML and then pass it into the desktop configuration. This serves as a
|
||||
//! proof-of-concept for the hydration feature, but you'll probably only want to use hydration for the web.
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus::ssr;
|
||||
|
||||
fn main() {
|
||||
let mut vdom = VirtualDom::launch_in_place(App);
|
||||
let content = ssr::render_vdom(&vdom, |f| f.pre_render(true));
|
||||
|
||||
dioxus::desktop::launch(App, |c| c.with_prerendered(content)).unwrap();
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
let mut val = use_state(cx, || 0);
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
h1 {"hello world. Count: {val}"}
|
||||
button {
|
||||
"click to increment"
|
||||
onclick: move |_| val += 1
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
+6
-4
@@ -15,17 +15,19 @@
|
||||
//! the RefCell will panic and crash. You can use `try_get_mut` or `.modify` to avoid this problem, or just not hold two
|
||||
//! RefMuts at the same time.
|
||||
|
||||
use dioxus::desktop::wry::application::dpi::LogicalSize;
|
||||
use dioxus::events::on::*;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_desktop::wry::application::dpi::LogicalSize;
|
||||
|
||||
const STYLE: &str = include_str!("./assets/calculator.css");
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
dioxus::desktop::launch(App, |cfg| {
|
||||
cfg.with_title("Calculator Demo")
|
||||
.with_resizable(false)
|
||||
.with_inner_size(LogicalSize::new(320.0, 530.0))
|
||||
cfg.with_window(|w| {
|
||||
w.with_title("Calculator Demo")
|
||||
.with_resizable(false)
|
||||
.with_inner_size(LogicalSize::new(320.0, 530.0))
|
||||
})
|
||||
})
|
||||
.expect("failed to launch dioxus app");
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ pub static Example: FC<()> = |cx| {
|
||||
|
||||
// Tasks are 'static, so we need to copy relevant items in
|
||||
let (async_count, dir) = (count.for_async(), *direction);
|
||||
|
||||
let (task, result) = use_task(cx, move || async move {
|
||||
// Count infinitely!
|
||||
loop {
|
||||
gloo_timers::future::TimeoutFuture::new(250).await;
|
||||
*async_count.get_mut() += dir;
|
||||
|
||||
@@ -7,7 +7,7 @@ pub static Example: FC<()> = |cx| {
|
||||
// This is an easy/low hanging fruit to improve upon
|
||||
let mut dom = VirtualDom::new(SomeApp);
|
||||
dom.rebuild_in_place().unwrap();
|
||||
ssr::render_vdom(&dom)
|
||||
ssr::render_vdom(&dom, |c| c)
|
||||
});
|
||||
|
||||
cx.render(rsx! {
|
||||
|
||||
+5
-3
@@ -1,13 +1,15 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus::ssr;
|
||||
|
||||
fn main() {
|
||||
let mut vdom = VirtualDom::new(App);
|
||||
vdom.rebuild_in_place();
|
||||
println!("{}", ssr::render_vdom(&vdom));
|
||||
vdom.rebuild_in_place().expect("Rebuilding failed");
|
||||
println!("{}", ssr::render_vdom(&vdom, |c| c));
|
||||
}
|
||||
|
||||
const App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx| {
|
||||
cx.render(rsx!(
|
||||
div {
|
||||
h1 { "Title" }
|
||||
|
||||
@@ -3,10 +3,12 @@ use dioxus::prelude::*;
|
||||
fn main() {
|
||||
use dioxus::desktop::wry::application::platform::macos::*;
|
||||
dioxus::desktop::launch(App, |c| {
|
||||
c.with_fullsize_content_view(true)
|
||||
.with_titlebar_buttons_hidden(false)
|
||||
.with_titlebar_transparent(true)
|
||||
.with_movable_by_window_background(true)
|
||||
c.with_window(|w| {
|
||||
w.with_fullsize_content_view(true)
|
||||
.with_titlebar_buttons_hidden(false)
|
||||
.with_titlebar_transparent(true)
|
||||
.with_movable_by_window_background(true)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+3
-7
@@ -1,14 +1,10 @@
|
||||
#![allow(non_upper_case_globals, non_snake_case)]
|
||||
use dioxus::prelude::*;
|
||||
use im_rc::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
fn main() {
|
||||
#[cfg(feature = "desktop")]
|
||||
// #[cfg(not(target_arch = "wasm32"))]
|
||||
dioxus::desktop::launch(App, |c| c);
|
||||
|
||||
#[cfg(feature = "desktop")]
|
||||
dioxus::web::launch(App, |c| c);
|
||||
fn main() -> anyhow::Result<()> {
|
||||
dioxus::desktop::launch(App, |c| c)
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
||||
+3
-2
@@ -8,12 +8,13 @@
|
||||
//! into the native VDom instance.
|
||||
//!
|
||||
//! Currently, NodeRefs won't work properly, but all other event functionality will.
|
||||
#![allow(non_upper_case_globals, non_snake_case)]
|
||||
|
||||
use dioxus::{events::on::MouseEvent, prelude::*};
|
||||
|
||||
fn main() {
|
||||
fn main() -> anyhow::Result<()> {
|
||||
env_logger::init();
|
||||
dioxus::desktop::launch(App, |c| c);
|
||||
dioxus::desktop::launch(App, |c| c)
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
|
||||
+1
-34
@@ -1,3 +1,4 @@
|
||||
#![allow(non_upper_case_globals, non_snake_case)]
|
||||
//! Example: Webview Renderer
|
||||
//! -------------------------
|
||||
//!
|
||||
@@ -11,53 +12,19 @@
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
// #[cfg]
|
||||
fn main() {
|
||||
// env_logger::init();
|
||||
dioxus::web::launch(App, |c| c);
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
dbg!("rednering parent");
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
But {
|
||||
h1 {"he"}
|
||||
}
|
||||
// But {
|
||||
// h1 {"llo"}
|
||||
// }
|
||||
// But {
|
||||
// h1 {"world"}
|
||||
// }
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
static But: FC<()> = |cx| {
|
||||
let mut count = use_state(cx, || 0);
|
||||
|
||||
// let d = Dropper { name: "asd" };
|
||||
// let handler = move |_| {
|
||||
// dbg!(d.name);
|
||||
// };
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
h1 { "Hifive counter: {count}" }
|
||||
{cx.children()}
|
||||
button { onclick: move |_| count += 1, "Up high!" }
|
||||
button { onclick: move |_| count -= 1, "Down low!" }
|
||||
// button { onclick: {handler}, "Down low!" }
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
// struct Dropper {
|
||||
// name: &'static str,
|
||||
// }
|
||||
// impl Drop for Dropper {
|
||||
// fn drop(&mut self) {
|
||||
// dbg!("dropped");
|
||||
// }
|
||||
// }
|
||||
Reference in new issue
Block a user