Skip to content

Commit 4debd9c

Browse files
authored
Merge pull request #1402 from ealmloff/events-2
Rework Event System
2 parents 5bd0abc + 4e6eee8 commit 4debd9c

Some content is hidden

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

76 files changed

+4640
-1084
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dioxus-core = { path = "packages/core", version = "0.4.2" }
5959
dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" }
6060
dioxus-router = { path = "packages/router", version = "0.4.1" }
6161
dioxus-router-macro = { path = "packages/router-macro", version = "0.4.1" }
62-
dioxus-html = { path = "packages/html", version = "0.4.0" }
62+
dioxus-html = { path = "packages/html", default-features = false, version = "0.4.0" }
6363
dioxus-hooks = { path = "packages/hooks", version = "0.4.0" }
6464
dioxus-web = { path = "packages/web", version = "0.4.0" }
6565
dioxus-ssr = { path = "packages/ssr", version = "0.4.0" }

examples/compose.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn app(cx: Scope) -> Element {
2626
button {
2727
onclick: move |_| {
2828
let dom = VirtualDom::new_with_props(compose, ComposeProps { app_tx: tx.clone() });
29-
window.new_window(dom, Default::default());
29+
dioxus_desktop::window().new_window(dom, Default::default());
3030
},
3131
"Click to compose a new email"
3232
}
@@ -62,10 +62,7 @@ fn compose(cx: Scope<ComposeProps>) -> Element {
6262
"Click to send"
6363
}
6464

65-
input {
66-
oninput: move |e| user_input.set(e.value.clone()),
67-
value: "{user_input}"
68-
}
65+
input { oninput: move |e| user_input.set(e.value()), value: "{user_input}" }
6966
}
7067
})
7168
}

examples/counter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn app(cx: Scope) -> Element {
2222
input {
2323
value: "{counter}",
2424
oninput: move |e| {
25-
if let Ok(value) = e.value.parse::<usize>() {
25+
if let Ok(value) = e.value().parse::<usize>() {
2626
counters.make_mut()[i] = value;
2727
}
2828
}

examples/crm.rs

Lines changed: 26 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ fn App(cx: Scope) -> Element {
3535
rel: "stylesheet",
3636
href: "https://unpkg.com/[email protected]/build/pure-min.css",
3737
integrity: "sha384-Uu6IeWbM+gzNVXJcM9XV3SohHtmWE+3VGi496jvgX1jyvDTXfdK+rfZc8C1Aehk5",
38-
crossorigin: "anonymous",
38+
crossorigin: "anonymous"
3939
}
4040

41-
style { "
41+
style {
42+
"
4243
.red {{
4344
background-color: rgb(202, 60, 60) !important;
4445
}}
45-
" }
46+
"
47+
}
4648

4749
h1 { "Dioxus CRM Example" }
4850

@@ -57,16 +59,8 @@ fn ClientList(cx: Scope) -> Element {
5759
cx.render(rsx! {
5860
h2 { "List of Clients" }
5961

60-
Link {
61-
to: Route::ClientAdd {},
62-
class: "pure-button pure-button-primary",
63-
"Add Client"
64-
}
65-
Link {
66-
to: Route::Settings {},
67-
class: "pure-button",
68-
"Settings"
69-
}
62+
Link { to: Route::ClientAdd {}, class: "pure-button pure-button-primary", "Add Client" }
63+
Link { to: Route::Settings {}, class: "pure-button", "Settings" }
7064

7165
clients.read().iter().map(|client| rsx! {
7266
div {
@@ -94,79 +88,55 @@ fn ClientAdd(cx: Scope) -> Element {
9488
class: "pure-form pure-form-aligned",
9589
onsubmit: move |_| {
9690
let mut clients = clients.write();
97-
98-
clients.push(Client {
99-
first_name: first_name.to_string(),
100-
last_name: last_name.to_string(),
101-
description: description.to_string(),
102-
});
103-
91+
clients
92+
.push(Client {
93+
first_name: first_name.to_string(),
94+
last_name: last_name.to_string(),
95+
description: description.to_string(),
96+
});
10497
dioxus_router::router().push(Route::ClientList {});
10598
},
10699

107100
fieldset {
108-
div {
109-
class: "pure-control-group",
110-
label {
111-
"for": "first_name",
112-
"First Name"
113-
}
101+
div { class: "pure-control-group",
102+
label { "for": "first_name", "First Name" }
114103
input {
115104
id: "first_name",
116105
"type": "text",
117106
placeholder: "First Name…",
118107
required: "",
119108
value: "{first_name}",
120-
oninput: move |e| first_name.set(e.value.clone())
109+
oninput: move |e| first_name.set(e.value())
121110
}
122111
}
123112

124-
div {
125-
class: "pure-control-group",
126-
label {
127-
"for": "last_name",
128-
"Last Name"
129-
}
113+
div { class: "pure-control-group",
114+
label { "for": "last_name", "Last Name" }
130115
input {
131116
id: "last_name",
132117
"type": "text",
133118
placeholder: "Last Name…",
134119
required: "",
135120
value: "{last_name}",
136-
oninput: move |e| last_name.set(e.value.clone())
121+
oninput: move |e| last_name.set(e.value())
137122
}
138123
}
139124

140-
div {
141-
class: "pure-control-group",
142-
label {
143-
"for": "description",
144-
"Description"
145-
}
125+
div { class: "pure-control-group",
126+
label { "for": "description", "Description" }
146127
textarea {
147128
id: "description",
148129
placeholder: "Description…",
149130
value: "{description}",
150-
oninput: move |e| description.set(e.value.clone())
131+
oninput: move |e| description.set(e.value())
151132
}
152133
}
153134

154-
div {
155-
class: "pure-controls",
156-
button {
157-
"type": "submit",
158-
class: "pure-button pure-button-primary",
159-
"Save"
160-
}
161-
Link {
162-
to: Route::ClientList {},
163-
class: "pure-button pure-button-primary red",
164-
"Cancel"
165-
}
135+
div { class: "pure-controls",
136+
button { "type": "submit", class: "pure-button pure-button-primary", "Save" }
137+
Link { to: Route::ClientList {}, class: "pure-button pure-button-primary red", "Cancel" }
166138
}
167139
}
168-
169-
170140
}
171141
})
172142
}
@@ -187,10 +157,6 @@ fn Settings(cx: Scope) -> Element {
187157
"Remove all Clients"
188158
}
189159

190-
Link {
191-
to: Route::ClientList {},
192-
class: "pure-button",
193-
"Go back"
194-
}
160+
Link { to: Route::ClientList {}, class: "pure-button", "Go back" }
195161
})
196162
}

examples/file_upload.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn App(cx: Scope) -> Element {
1616
r#type: "checkbox",
1717
checked: "{enable_directory_upload}",
1818
oninput: move |evt| {
19-
enable_directory_upload.set(evt.value.parse().unwrap());
19+
enable_directory_upload.set(evt.value().parse().unwrap());
2020
},
2121
},
2222
"Enable directory upload"
@@ -30,7 +30,7 @@ fn App(cx: Scope) -> Element {
3030
onchange: |evt| {
3131
to_owned![files_uploaded];
3232
async move {
33-
if let Some(file_engine) = &evt.files {
33+
if let Some(file_engine) = &evt.files() {
3434
let files = file_engine.files();
3535
for file_name in files {
3636
sleep(std::time::Duration::from_secs(1)).await;

examples/form.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ fn app(cx: Scope) -> Element {
1414
div {
1515
h1 { "Form" }
1616
form {
17-
onsubmit: move |ev| println!("Submitted {:?}", ev.values),
18-
oninput: move |ev| println!("Input {:?}", ev.values),
17+
onsubmit: move |ev| println!("Submitted {:?}", ev.values()),
18+
oninput: move |ev| println!("Input {:?}", ev.values()),
1919
input { r#type: "text", name: "username" }
2020
input { r#type: "text", name: "full-name" }
2121
input { r#type: "password", name: "password" }

examples/login_form.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ fn app(cx: Scope) -> Element {
1212
let resp = reqwest::Client::new()
1313
.post("http://localhost:8080/login")
1414
.form(&[
15-
("username", &evt.values["username"]),
16-
("password", &evt.values["password"]),
15+
("username", &evt.values()["username"]),
16+
("password", &evt.values()["password"]),
1717
])
1818
.send()
1919
.await;
@@ -31,8 +31,7 @@ fn app(cx: Scope) -> Element {
3131

3232
cx.render(rsx! {
3333
h1 { "Login" }
34-
form {
35-
onsubmit: onsubmit,
34+
form { onsubmit: onsubmit,
3635
input { r#type: "text", id: "username", name: "username" }
3736
label { "Username" }
3837
br {}

examples/shared_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn DataEditor(cx: Scope, id: usize) -> Element {
6464
fn DataView(cx: Scope, id: usize) -> Element {
6565
let cool_data = use_shared_state::<CoolData>(cx).unwrap();
6666

67-
let oninput = |e: FormEvent| cool_data.write().set(*id, e.value.clone());
67+
let oninput = |e: FormEvent| cool_data.write().set(*id, e.value());
6868

6969
let cool_data = cool_data.read();
7070
let my_data = &cool_data.view(id).unwrap();

examples/textarea.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn app(cx: Scope) -> Element {
1717
rows: "10",
1818
cols: "80",
1919
value: "{model}",
20-
oninput: move |e| model.set(e.value.clone()),
20+
oninput: move |e| model.set(e.value().clone()),
2121
}
2222
})
2323
}

examples/todomvc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn TodoHeader<'a>(cx: Scope<'a, TodoHeaderProps<'a>>) -> Element {
107107
value: "{draft}",
108108
autofocus: "true",
109109
oninput: move |evt| {
110-
draft.set(evt.value.clone());
110+
draft.set(evt.value().clone());
111111
},
112112
onkeydown: move |evt| {
113113
if evt.key() == Key::Enter && !draft.is_empty() {
@@ -154,7 +154,7 @@ pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
154154
id: "cbg-{todo.id}",
155155
checked: "{todo.checked}",
156156
oninput: move |evt| {
157-
cx.props.todos.make_mut()[&cx.props.id].checked = evt.value.parse().unwrap();
157+
cx.props.todos.make_mut()[&cx.props.id].checked = evt.value().parse().unwrap();
158158
}
159159
}
160160
label {
@@ -175,7 +175,7 @@ pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
175175
input {
176176
class: "edit",
177177
value: "{todo.contents}",
178-
oninput: move |evt| cx.props.todos.make_mut()[&cx.props.id].contents = evt.value.clone(),
178+
oninput: move |evt| cx.props.todos.make_mut()[&cx.props.id].contents = evt.value(),
179179
autofocus: "true",
180180
onfocusout: move |_| is_editing.set(false),
181181
onkeydown: move |evt| {

0 commit comments

Comments
 (0)