Skip to content

Commit cda759c

Browse files
committed
examples: upgrade to new version of dioxus core.
also add the inline_props macro
1 parent 21e00c1 commit cda759c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+558
-255
lines changed

examples/async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub static App: Component<()> = |cx| {
1717

1818
let (async_count, dir) = (count.for_async(), *direction);
1919

20-
let (task, _) = use_coroutine(cx, move || async move {
20+
let task = use_coroutine(&cx, move || async move {
2121
loop {
2222
TimeoutFuture::new(250).await;
2323
*async_count.get_mut() += dir;

examples/borrowed.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct C1Props<'a> {
4040
}
4141

4242
fn Child1<'a>(cx: Scope<'a, C1Props<'a>>) -> Element {
43-
let (left, right) = props.text.split_once("=").unwrap();
43+
let (left, right) = cx.props.text.split_once("=").unwrap();
4444

4545
cx.render(rsx! {
4646
div {
@@ -58,7 +58,7 @@ struct C2Props<'a> {
5858
fn Child2<'a>(cx: Scope<'a, C2Props<'a>>) -> Element {
5959
cx.render(rsx! {
6060
Child3 {
61-
text: props.text
61+
text: cx.props.text
6262
}
6363
})
6464
}

examples/calculator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,6 @@ fn CalculatorKey<'a>(cx: Scope<'a, CalculatorKeyProps<'a>>) -> Element {
124124
rsx!(cx, button {
125125
class: "calculator-key {cx.props.name}"
126126
onclick: {cx.props.onclick}
127-
{&props.children}
127+
{&cx.props.children}
128128
})
129129
}

examples/coroutine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ static App: Component<()> = |cx| {
5858
#[derive(Props)]
5959
struct HorseyProps<'a> {
6060
pos: i32,
61-
children: ScopeChildren<'a>,
61+
children: Element<'a>,
6262
}
6363

64-
fn Horsey<'a>((cx, props): ScopeState<'a, HorseyProps<'a>>) -> Element {
64+
fn Horsey<'a>(cx: Scope<'a, HorseyProps<'a>>) -> Element {
6565
cx.render(rsx! {
6666
div {
6767
button { "pause" }
6868
div {
69-
{&props.children}
69+
{&cx.props.children}
7070
}
7171
}
7272
})

examples/file_explorer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use dioxus::prelude::*;
99

1010
fn main() {
11-
simple_logger::init_with_level(log::Level::Debug);
11+
// simple_logger::init_with_level(log::Level::Debug);
1212
dioxus::desktop::launch_cfg(App, |c| {
1313
c.with_window(|w| {
1414
w.with_resizable(true).with_inner_size(

examples/framework_benchmark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct ActionButtonProps<'a> {
9797

9898
fn ActionButton<'a>(cx: Scope<'a, ActionButtonProps<'a>>) -> Element {
9999
rsx!(cx, div { class: "col-sm-6 smallpad"
100-
button { class:"btn btn-primary btn-block", r#type: "button", id: "{cx.props.id}", onclick: move |_| (props.onclick)(),
100+
button { class:"btn btn-primary btn-block", r#type: "button", id: "{cx.props.id}", onclick: move |_| (cx.props.onclick)(),
101101
"{cx.props.name}"
102102
}
103103
})

examples/hello_world.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use dioxus::prelude::*;
22

33
fn main() {
4-
dioxus::desktop::launch(App);
4+
dioxus::desktop::launch(app);
55
}
66

7-
fn App((cx, props): ScopeState<()>) -> Element {
7+
fn app(cx: Scope<()>) -> Element {
88
cx.render(rsx! (
99
div { "Hello, world!" }
1010
))

examples/hydration.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use dioxus::ssr;
1414

1515
fn main() {
1616
let vdom = VirtualDom::new(App);
17-
let content = ssr::render_vdom(&vdom, |f| f.pre_render(true));
17+
let content = ssr::render_vdom_cfg(&vdom, |f| f.pre_render(true));
1818

19-
dioxus::desktop::launch(App, |c| c.with_prerendered(content));
19+
dioxus::desktop::launch_cfg(App, |c| c.with_prerendered(content));
2020
}
2121

2222
static App: Component<()> = |cx| {

examples/manual_edits.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ fn main() {
3333
AppendChildren { many: 1 },
3434
];
3535

36-
dioxus_desktop::run(APP, (), |c| c.with_edits(edits));
37-
}
36+
let app: Component<()> = |cx| rsx!(cx, div { "some app" });
3837

39-
const APP: Component<()> = |(cx, _props)| {
40-
rsx!(cx, div {
41-
"some app"
42-
})
43-
};
38+
dioxus_desktop::run(app, (), |c| c.with_edits(edits));
39+
}

examples/pattern_model.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//! the RefCell will panic and crash. You can use `try_get_mut` or `.modify` to avoid this problem, or just not hold two
1616
//! RefMuts at the same time.
1717
18+
use std::sync::Arc;
19+
1820
use dioxus::desktop::wry::application::dpi::LogicalSize;
1921
use dioxus::events::*;
2022
use dioxus::prelude::*;
@@ -73,16 +75,16 @@ static App: Component<()> = |cx| {
7375
#[derive(Props)]
7476
struct CalculatorKeyProps<'a> {
7577
name: &'static str,
76-
onclick: &'a dyn Fn(MouseEvent),
77-
children: ScopeChildren<'a>,
78+
onclick: &'a dyn Fn(Arc<MouseEvent>),
79+
children: Element<'a>,
7880
}
7981

80-
fn CalculatorKey<'a>((cx, props): ScopeState<'a, CalculatorKeyProps<'a>>) -> Element<'a> {
82+
fn CalculatorKey<'a>(cx: Scope<'a, CalculatorKeyProps<'a>>) -> Element {
8183
cx.render(rsx! {
8284
button {
8385
class: "calculator-key {cx.props.name}"
84-
onclick: {cx.props.onclick}
85-
{&props.children}
86+
onclick: move |e| (cx.props.onclick)(e)
87+
{&cx.props.children}
8688
}
8789
})
8890
}
@@ -168,7 +170,7 @@ impl Calculator {
168170
self.cur_val = self.display_value.parse::<f64>().unwrap();
169171
self.waiting_for_operand = true;
170172
}
171-
fn handle_keydown(&mut self, evt: KeyboardEvent) {
173+
fn handle_keydown(&mut self, evt: Arc<KeyboardEvent>) {
172174
match evt.key_code {
173175
KeyCode::Backspace => self.backspace(),
174176
KeyCode::Num0 => self.input_digit(0),

examples/router.rs

+2-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use dioxus::prelude::*;
2-
use dioxus::router::Router;
2+
use dioxus_router::{use_router, Link};
33

44
#[derive(PartialEq, Debug, Clone)]
55
pub enum Route {
@@ -24,7 +24,7 @@ pub enum Route {
2424
}
2525

2626
static App: Component<()> = |cx| {
27-
let route = use_router(cx, Route::parse)?;
27+
let route = use_router(&cx, Route::parse);
2828

2929
cx.render(rsx! {
3030
nav {
@@ -61,26 +61,4 @@ impl Route {
6161
}
6262
}
6363

64-
impl Routable for Route {
65-
fn from_path(path: &str, params: &std::collections::HashMap<&str, &str>) -> Option<Self> {
66-
todo!()
67-
}
68-
69-
fn to_path(&self) -> String {
70-
todo!()
71-
}
72-
73-
fn routes() -> Vec<&'static str> {
74-
todo!()
75-
}
76-
77-
fn not_found_route() -> Option<Self> {
78-
todo!()
79-
}
80-
81-
fn recognize(pathname: &str) -> Option<Self> {
82-
todo!()
83-
}
84-
}
85-
8664
fn main() {}

examples/rsx_usage.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
//! - Allow top-level fragments
4040
//!
4141
fn main() {
42-
dioxus::desktop::launch(Example);
42+
dioxus::desktop::launch(EXAMPLE);
4343
}
4444

4545
/// When trying to return "nothing" to Dioxus, you'll need to specify the type parameter or Rust will be sad.
@@ -49,7 +49,7 @@ const NONE_ELEMENT: Option<()> = None;
4949
use baller::Baller;
5050
use dioxus::prelude::*;
5151

52-
pub static Example: Component<()> = |cx| {
52+
pub static EXAMPLE: Component<()> = |cx| {
5353
let formatting = "formatting!";
5454
let formatting_tuple = ("a", "b");
5555
let lazy_fmt = format_args!("lazily formatted text");
@@ -173,12 +173,12 @@ pub static Example: Component<()> = |cx| {
173173
Taller { a: "asd", div {"hello world!"} }
174174

175175
// helper functions
176-
{helper(cx, "hello world!")}
176+
{helper(&cx, "hello world!")}
177177
}
178178
})
179179
};
180180

181-
fn helper(cx: Scope, text: &str) -> Element {
181+
fn helper<'a>(cx: &'a ScopeState, text: &str) -> Element<'a> {
182182
rsx!(cx, p { "{text}" })
183183
}
184184

@@ -188,21 +188,19 @@ mod baller {
188188
pub struct BallerProps {}
189189

190190
/// This component totally balls
191-
pub fn Baller(_: ScopeState<BallerProps>) -> Element {
191+
pub fn Baller(_: Scope<BallerProps>) -> Element {
192192
todo!()
193193
}
194194
}
195195

196196
#[derive(Props)]
197197
pub struct TallerProps<'a> {
198198
a: &'static str,
199-
200-
#[builder(default)]
201-
children: ScopeChildren<'a>,
199+
children: Element<'a>,
202200
}
203201

204202
/// This component is taller than most :)
205-
pub fn Taller<'a>(_: ScopeState<'a, TallerProps<'a>>) -> Element {
203+
pub fn Taller<'a>(_: Scope<'a, TallerProps<'a>>) -> Element {
206204
let b = true;
207205
todo!()
208206
}

examples/ssr.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
#![allow(non_upper_case_globals)]
2-
31
use dioxus::prelude::*;
42
use dioxus::ssr;
53

64
fn main() {
7-
let mut vdom = VirtualDom::new(App);
8-
vdom.rebuild_in_place().expect("Rebuilding failed");
5+
let mut vdom = VirtualDom::new(APP);
6+
let _ = vdom.rebuild();
97
println!("{}", ssr::render_vdom(&vdom));
108
}
119

12-
static App: Component<()> = |cx| {
10+
static APP: Component<()> = |cx| {
1311
cx.render(rsx!(
1412
div {
1513
h1 { "Title" }
1614
p { "Body" }
1715
}
1816
))
1917
};
20-
21-
struct MyProps<'a> {
22-
text: &'a str,
23-
}
24-
fn App2<'a>(cx: Scope<'a, MyProps<'a>>) -> Element {
25-
None
26-
}

examples/tailwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
22

33
fn main() {
44
use dioxus::desktop::wry::application::platform::macos::*;
5-
dioxus::desktop::launch(App, |c| {
5+
dioxus::desktop::launch_cfg(App, |c| {
66
c.with_window(|w| {
77
w.with_fullsize_content_view(true)
88
.with_titlebar_buttons_hidden(false)

examples/tasks.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,24 @@ use std::time::Duration;
66

77
use dioxus::prelude::*;
88
fn main() {
9-
dioxus::desktop::launch(App);
9+
dioxus::desktop::launch(app);
1010
}
1111

12-
static App: Component<()> = |cx| {
12+
fn app(cx: Scope<()>) -> Element {
1313
let mut count = use_state(&cx, || 0);
1414

15-
cx.push_task(async move {
15+
cx.push_task(|| async move {
1616
tokio::time::sleep(Duration::from_millis(100)).await;
17-
println!("setting count");
1817
count += 1;
19-
// count.set(10);
20-
// *count += 1;
21-
// let c = count.get() + 1;
22-
// count.set(c);
2318
});
2419

2520
cx.render(rsx! {
2621
div {
2722
h1 { "High-Five counter: {count}" }
28-
// button {
29-
// onclick: move |_| count +=1 ,
30-
// "Click me!"
31-
// }
23+
button {
24+
onclick: move |_| count +=1 ,
25+
"Click me!"
26+
}
3227
}
3328
})
34-
};
29+
}

examples/todomvc.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub struct TodoItem {
2323

2424
const STYLE: &str = include_str!("./assets/todomvc.css");
2525
const App: Component<()> = |cx| {
26-
let mut draft = use_state(&cx, || "".to_string());
27-
let mut todos = use_state(&cx, || HashMap::<u32, Rc<TodoItem>>::new());
28-
let mut filter = use_state(&cx, || FilterState::All);
26+
let draft = use_state(&cx, || "".to_string());
27+
let todos = use_state(&cx, || HashMap::<u32, Rc<TodoItem>>::new());
28+
let filter = use_state(&cx, || FilterState::All);
2929

3030
let todolist = todos
3131
.iter()
@@ -86,9 +86,9 @@ pub struct TodoEntryProps {
8686
}
8787

8888
pub fn TodoEntry(cx: Scope<TodoEntryProps>) -> Element {
89-
let mut is_editing = use_state(&cx, || false);
90-
let mut contents = use_state(&cx, || String::from(""));
91-
let todo = &props.todo;
89+
let is_editing = use_state(&cx, || false);
90+
let contents = use_state(&cx, || String::from(""));
91+
let todo = &cx.props.todo;
9292

9393
rsx!(cx, li {
9494
"{todo.id}"

examples/web_tick.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ struct RowProps {
4545
row_id: usize,
4646
label: Label,
4747
}
48-
fn Row((cx, props): ScopeState<RowProps>) -> Element {
49-
let [adj, col, noun] = props.label.0;
48+
fn Row(cx: Scope<RowProps>) -> Element {
49+
let [adj, col, noun] = cx.props.label.0;
5050
cx.render(rsx! {
5151
tr {
5252
td { class:"col-md-1", "{cx.props.row_id}" }

packages/core-macro/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "dioxus-core-macro"
33
version = "0.1.2"
44
authors = ["Jonathan Kelley"]
5-
edition = "2018"
5+
edition = "2021"
66
description = "Core macro for Dioxus Virtual DOM"
77
license = "MIT/Apache-2.0"
88
repository = "https://github.com/DioxusLabs/dioxus/"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use dioxus_core_macro::{inline_props, Props};
2+
3+
fn main() {}
4+
5+
type Element<'a> = ();
6+
7+
pub struct Scope<'a, T> {
8+
props: &'a T,
9+
}
10+
11+
#[inline_props]
12+
pub fn component(
13+
cx: Scope,
14+
chkk: String,
15+
chkk2: String,
16+
r: u32,
17+
cat: &'a str,
18+
drd: String,
19+
e: String,
20+
) -> Element {
21+
let r = chkk.len();
22+
}

0 commit comments

Comments
 (0)