wip: move examples around
This commit is contained in:
1 parent
269e81b0fd
commit
304259d818
24 files changed
+81
-71
No files matched your search
+21
-15
@@ -8,16 +8,26 @@ description = "Core functionality for Dioxus - a concurrent renderer-agnostic Vi
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dioxus-core = { path="./packages/core", version="0.1.0" }
|
dioxus-core = { path = "./packages/core" }
|
||||||
dioxus-core-macro = { path="./packages/core-macro", version="0.1.0", optional=true }
|
dioxus-core-macro = { path = "./packages/core-macro", optional = true }
|
||||||
dioxus-html = { path="./packages/html", optional=true }
|
dioxus-html = { path = "./packages/html", optional = true }
|
||||||
dioxus-web = { path="./packages/web", optional=true }
|
dioxus-web = { path = "./packages/web", optional = true }
|
||||||
dioxus-webview = { path="./packages/webview", optional=true }
|
dioxus-webview = { path = "./packages/webview", optional = true }
|
||||||
dioxus-hooks = { path="./packages/hooks", version="0.0.0", optional=true }
|
dioxus-hooks = { path = "./packages/hooks", optional = true }
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["macro", "ssr", "hooks", "router", "core", "atoms", "html", "web", "desktop"]
|
default = [
|
||||||
|
"core",
|
||||||
|
"atoms",
|
||||||
|
"macro",
|
||||||
|
"ssr",
|
||||||
|
"hooks",
|
||||||
|
"router",
|
||||||
|
"html",
|
||||||
|
"web",
|
||||||
|
"desktop",
|
||||||
|
]
|
||||||
atoms = []
|
atoms = []
|
||||||
macro = ["dioxus-core-macro"]
|
macro = ["dioxus-core-macro"]
|
||||||
ssr = []
|
ssr = []
|
||||||
@@ -31,29 +41,25 @@ desktop = ["dioxus-webview"]
|
|||||||
core = []
|
core = []
|
||||||
|
|
||||||
|
|
||||||
[profile.dev]
|
|
||||||
split-debuginfo = "unpacked"
|
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures = "0.3.15"
|
futures = "0.3.15"
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
num-format = "0.4.0"
|
num-format = "0.4.0"
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
separator = "0.4.1"
|
separator = "0.4.1"
|
||||||
serde = { version="1.0.126", features=["derive"] }
|
serde = { version = "1.0.126", features = ["derive"] }
|
||||||
surf = "2.2.0"
|
surf = "2.2.0"
|
||||||
env_logger = "*"
|
env_logger = "*"
|
||||||
async-std = { version="1.9.0", features=["attributes"] }
|
async-std = { version = "1.9.0", features = ["attributes"] }
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"packages/core-macro",
|
|
||||||
"packages/core",
|
"packages/core",
|
||||||
|
"packages/core-macro",
|
||||||
"packages/html",
|
"packages/html",
|
||||||
|
"packages/hooks",
|
||||||
"packages/web",
|
"packages/web",
|
||||||
"packages/webview",
|
"packages/webview",
|
||||||
"packages/hooks",
|
|
||||||
"packages/ssr",
|
"packages/ssr",
|
||||||
# "packages/atoms",
|
# "packages/atoms",
|
||||||
# "packages/docsite",
|
# "packages/docsite",
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ static AntipatternNestedFragments: FC<()> = |cx| {
|
|||||||
/// recognize from the function signature, but Dioxus will not update the "live" version of state. Calling `set_state`
|
/// recognize from the function signature, but Dioxus will not update the "live" version of state. Calling `set_state`
|
||||||
/// merely places a new value in the queue and schedules the component for a future update.
|
/// merely places a new value in the queue and schedules the component for a future update.
|
||||||
static AntipaternRelyingOnSetState: FC<()> = |cx| {
|
static AntipaternRelyingOnSetState: FC<()> = |cx| {
|
||||||
let (state, set_state) = use_state_classic(cx, || "Hello world");
|
let (state, set_state) = use_state(cx, || "Hello world").classic();
|
||||||
set_state("New state");
|
set_state("New state");
|
||||||
// This will return false! `state` will *still* be "Hello world"
|
// This will return false! `state` will *still* be "Hello world"
|
||||||
assert!(state == &"New state");
|
assert!(state == &"New state");
|
||||||
@@ -126,7 +126,7 @@ static AntipatternMisusedHooks: FC<MisuedHooksProps> = |cx| {
|
|||||||
if cx.should_render_state {
|
if cx.should_render_state {
|
||||||
// do not place a hook in the conditional!
|
// do not place a hook in the conditional!
|
||||||
// prefer to move it out of the conditional
|
// prefer to move it out of the conditional
|
||||||
let (state, set_state) = use_state_classic(cx, || "hello world");
|
let (state, set_state) = use_state(cx, || "hello world").classic();
|
||||||
rsx!(in cx, div { "{state}" })
|
rsx!(in cx, div { "{state}" })
|
||||||
} else {
|
} else {
|
||||||
rsx!(in cx, div { "Not rendering state" })
|
rsx!(in cx, div { "Not rendering state" })
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
//!
|
//!
|
||||||
//! This is a simple pattern that allows you to return no elements!
|
//! This is a simple pattern that allows you to return no elements!
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
use dioxus::prelude::*;
|
||||||
static Example: FC<()> = |cx| {
|
static Example: FC<()> = |cx| cx.render(rsx! { Fragment {} });
|
||||||
//
|
|
||||||
cx.render(rsx! {})
|
|
||||||
};
|
|
||||||
@@ -35,11 +35,12 @@ static Example2: FC<()> = |cx| {
|
|||||||
|
|
||||||
// Using the `fragment` method on the NodeFactory
|
// Using the `fragment` method on the NodeFactory
|
||||||
static Example3: FC<()> = |cx| {
|
static Example3: FC<()> = |cx| {
|
||||||
cx.render(LazyNodes::new(move |fac: &NodeFactory| {
|
cx.render(LazyNodes::new(move |fac| {
|
||||||
fac.fragment_builder(None, |list| {
|
fac.fragment_from_iter([
|
||||||
list.add_child(fac.text(format_args!("A")))
|
fac.text(format_args!("A")),
|
||||||
.add_child(fac.text(format_args!("B")))
|
fac.text(format_args!("B")),
|
||||||
.finish()
|
fac.text(format_args!("A")),
|
||||||
})
|
fac.text(format_args!("B")),
|
||||||
|
])
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
@@ -2,11 +2,11 @@ use dioxus::prelude::*;
|
|||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
||||||
static Example: FC<()> = |cx| {
|
static Example: FC<()> = |cx| {
|
||||||
let (g, set_g) = use_state_classic(cx, || 0);
|
let g = use_state(cx, || 0);
|
||||||
let v = (0..10).map(|f| {
|
let v = (0..10).map(|f| {
|
||||||
rsx! {
|
rsx! {
|
||||||
li {
|
li {
|
||||||
onclick: move |_| set_g(10)
|
onclick: move |_| g.set(10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ fn main() {}
|
|||||||
|
|
||||||
/// We can use `set_name` in multiple closures; the closures automatically *copy* the reference to set_name.
|
/// We can use `set_name` in multiple closures; the closures automatically *copy* the reference to set_name.
|
||||||
static ButtonList: FC<()> = |cx| {
|
static ButtonList: FC<()> = |cx| {
|
||||||
let (name, set_name) = use_state_classic(cx, || "...?");
|
let name = use_state(cx, || "...?");
|
||||||
|
|
||||||
let names = ["jack", "jill", "john", "jane"]
|
let names = ["jack", "jill", "john", "jane"]
|
||||||
.iter()
|
.iter()
|
||||||
.map(move |n| rsx!(button { onclick: move |_| set_name(n), "{n}" }));
|
.map(move |n| rsx!(button { onclick: move |_| name.set(n), "{n}" }));
|
||||||
|
|
||||||
cx.render(rsx!(
|
cx.render(rsx!(
|
||||||
div {
|
div {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ struct DogApi {
|
|||||||
const ENDPOINT: &str = "https://dog.ceo/api/breeds/image/random";
|
const ENDPOINT: &str = "https://dog.ceo/api/breeds/image/random";
|
||||||
|
|
||||||
pub static App: FC<()> = |cx| {
|
pub static App: FC<()> = |cx| {
|
||||||
let doggo = use_future_effect(&cx, move || async move {
|
let doggo = use_future_effect(cx, move || async move {
|
||||||
match surf::get(ENDPOINT).recv_json::<DogApi>().await {
|
match surf::get(ENDPOINT).recv_json::<DogApi>().await {
|
||||||
Ok(res) => rsx!(in cx, img { src: "{res.message}" }),
|
Ok(res) => rsx!(in cx, img { src: "{res.message}" }),
|
||||||
Err(_) => rsx!(in cx, div { "No doggos for you :(" }),
|
Err(_) => rsx!(in cx, div { "No doggos for you :(" }),
|
||||||
@@ -31,29 +31,33 @@ pub static App: FC<()> = |cx| {
|
|||||||
))
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
use dioxus_core::virtual_dom::SuspendedContext;
|
// use dioxus_core::virtual_dom::SuspendedContext;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
fn use_fetch<'a, T: serde::de::DeserializeOwned + 'static>(
|
|
||||||
cx: &impl Scoped<'a>,
|
fn use_fetch<'a, T, P, F>(cx: Context<P>, url: &str, g: F) -> VNode<'a>
|
||||||
url: &str,
|
where
|
||||||
g: impl FnOnce(SuspendedContext, surf::Result<T>) -> VNode<'a> + 'a,
|
T: serde::de::DeserializeOwned + 'static,
|
||||||
) -> VNode<'a> {
|
// F: FnOnce(SuspendedContext, surf::Result<T>) -> VNode<'a> + 'a,
|
||||||
// essentially we're doing a "use_effect" but with no dependent props or post-render shenanigans
|
F: FnOnce((), surf::Result<T>) -> VNode<'a> + 'a,
|
||||||
let fetch_promise = cx.use_hook(
|
{
|
||||||
move || surf::get(url).recv_json::<T>().boxed_local(),
|
todo!()
|
||||||
// just pass the future through
|
// // essentially we're doing a "use_effect" but with no dependent props or post-render shenanigans
|
||||||
|p| p,
|
// let fetch_promise = cx.use_hook(
|
||||||
|_| (),
|
// move || surf::get(url).recv_json::<T>().boxed_local(),
|
||||||
);
|
// // just pass the future through
|
||||||
cx.suspend(fetch_promise, g)
|
// |p| p,
|
||||||
|
// |_| (),
|
||||||
|
// );
|
||||||
|
// cx.suspend(fetch_promise, g)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawns the future only when the inputs change
|
/// Spawns the future only when the inputs change
|
||||||
fn use_future_effect<'a, 'b, F: Future<Output = VNode<'b>>>(
|
fn use_future_effect<'a, 'b, F, P, F2>(cx: Context<P>, g: F2) -> VNode<'a>
|
||||||
cx: &impl Scoped<'a>,
|
where
|
||||||
g: impl FnOnce() -> F + 'a,
|
F: Future<Output = VNode<'b>>,
|
||||||
) -> VNode<'a> {
|
F2: FnOnce() -> F + 'a,
|
||||||
|
{
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@@ -14,8 +14,15 @@ use dioxus::{builder::ElementBuilder, prelude::NodeFactory};
|
|||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
||||||
// TODO
|
mod dioxus_elements {
|
||||||
struct MyEle<'a, 'b> {
|
use dioxus::prelude::DioxusElement;
|
||||||
el: ElementBuilder<'a, 'b>,
|
|
||||||
fac: &'b NodeFactory<'a>,
|
struct custom_element;
|
||||||
|
impl DioxusElement for custom_element {
|
||||||
|
const TAG_NAME: &'static str = "custom_element";
|
||||||
|
const NAME_SPACE: Option<&'static str> = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-export the normal html namespace
|
||||||
|
pub use dioxus::prelude::dioxus_elements::*;
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -356,7 +356,9 @@ impl ToTokens for ToToksCtx<&TextNode> {
|
|||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let mut token_stream = TokenStream2::new();
|
let mut token_stream = TokenStream2::new();
|
||||||
self.recurse(&self.inner.0).to_tokens(&mut token_stream);
|
self.recurse(&self.inner.0).to_tokens(&mut token_stream);
|
||||||
tokens.append_all(quote! {dioxus::builder::text3(bump, format_args_f!(#token_stream))});
|
tokens.append_all(quote! {
|
||||||
|
__cx.text(format_args_f!(#token_stream))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ description = "Core functionality for Dioxus - a concurrent renderer-agnostic Vi
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# todo: use wast for faster load/compile
|
# todo: use wast for faster load/compile
|
||||||
dioxus-core-macro = { path="../core-macro", version="0.1.1" }
|
dioxus-core-macro = { path = "../core-macro", version = "0.1.1" }
|
||||||
|
|
||||||
# Bumpalo is used as a micro heap backing each component
|
# Bumpalo is used as a micro heap backing each component
|
||||||
bumpalo = { version="3.6.0", features=["collections", "boxed"] }
|
bumpalo = { version = "3.6.0", features = ["collections", "boxed"] }
|
||||||
|
|
||||||
# custom error type
|
# custom error type
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
@@ -29,7 +29,7 @@ longest-increasing-subsequence = "0.1.0"
|
|||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
# # Serialize the Edits for use in Webview/Liveview instances
|
# # Serialize the Edits for use in Webview/Liveview instances
|
||||||
serde = { version="1", features=["derive"], optional=true }
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
|
|
||||||
# Backs scopes and unique keys
|
# Backs scopes and unique keys
|
||||||
slotmap = "1.0.3"
|
slotmap = "1.0.3"
|
||||||
@@ -38,12 +38,6 @@ appendlist = "1.4.0"
|
|||||||
|
|
||||||
futures-util = "0.3.15"
|
futures-util = "0.3.15"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
dioxus-html = { path="../html" }
|
|
||||||
dioxus-hooks = { path="../hooks" }
|
|
||||||
env_logger = "*"
|
|
||||||
# async-std = { version="1.9.0", features=["attributes"] }
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
serialize = ["slotmap/serde", "serde"]
|
serialize = ["slotmap/serde", "serde"]
|
||||||
@@ -43,12 +43,12 @@ pub struct VirtualDom {
|
|||||||
|
|
||||||
/// The index of the root component
|
/// The index of the root component
|
||||||
/// Should always be the first (gen=0, id=0)
|
/// Should always be the first (gen=0, id=0)
|
||||||
pub(crate) base_scope: ScopeIdx,
|
pub base_scope: ScopeIdx,
|
||||||
|
|
||||||
/// All components dump their updates into a queue to be processed
|
/// All components dump their updates into a queue to be processed
|
||||||
pub(crate) event_queue: EventQueue,
|
pub event_queue: EventQueue,
|
||||||
|
|
||||||
pub(crate) tasks: TaskQueue,
|
pub tasks: TaskQueue,
|
||||||
|
|
||||||
root_props: std::pin::Pin<Box<dyn std::any::Any>>,
|
root_props: std::pin::Pin<Box<dyn std::any::Any>>,
|
||||||
|
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ edition = "2018"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dioxus-core = { path = "../core" }
|
dioxus-core = { path = "../../packages/core", version = "*" }
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
mod usestate;
|
mod usestate;
|
||||||
pub use usestate::{use_state, UseState};
|
pub use usestate::use_state;
|
||||||
Reference in new issue
Block a user