feat: add update functionality to useref

This commit is contained in:
Jonathan Kelley committed 2021-10-04 10:22:20 -04:00
1 parent 5502429626
commit a2b0c50a34
16 files changed
+77 -47

No files matched your search

+2 -2
View File
@@ -3,7 +3,7 @@ This example is a simple iOS-style calculator. This particular example can run a
This calculator version uses React-style state management. All state is held as individual use_states.
*/
use dioxus::events::on::*;
use dioxus::events::*;
use dioxus::prelude::*;
fn main() {
@@ -56,7 +56,7 @@ const APP: FC<()> = |cx, _| {
}
};
let keydownhandler = move |evt: KeyboardEvent| match evt.key_code() {
let keydownhandler = move |evt: KeyboardEvent| match evt.key_code {
KeyCode::Add => operator.set(Some("+")),
KeyCode::Subtract => operator.set(Some("-")),
KeyCode::Divide => operator.set(Some("/")),
+3 -3
View File
@@ -59,13 +59,13 @@ static App: FC<()> = |cx, _| {
h2 {"Add new client" margin_bottom: "10px" }
form { class: "pure-form"
input { class: "new-client firstname" placeholder: "First name" value: "{firstname}"
oninput: move |e| firstname.set(e.value())
oninput: move |e| firstname.set(e.value.clone())
}
input { class: "new-client lastname" placeholder: "Last name" value: "{lastname}"
oninput: move |e| lastname.set(e.value())
oninput: move |e| lastname.set(e.value.clone())
}
textarea { class: "new-client description" placeholder: "Description" value: "{description}"
oninput: move |e| description.set(e.value())
oninput: move |e| description.set(e.value.clone())
}
}
button { class: "pure-button pure-button-primary", onclick: {add_new}, "Add New" }
+8 -4
View File
@@ -8,11 +8,11 @@
use dioxus::prelude::*;
fn main() {
env_logger::init();
simple_logger::init_with_level(log::Level::Debug);
dioxus::desktop::launch(App, |c| {
c.with_window(|w| {
w.with_resizable(false).with_inner_size(
dioxus::desktop::wry::application::dpi::LogicalSize::new(800.0, 400.0),
w.with_resizable(true).with_inner_size(
dioxus::desktop::wry::application::dpi::LogicalSize::new(400.0, 800.0),
)
})
})
@@ -70,6 +70,7 @@ impl Files {
fn reload_path_list(&mut self) {
let cur_path = self.path_stack.last().unwrap();
log::info!("Reloading path list for {:?}", cur_path);
let paths = match std::fs::read_dir(cur_path) {
Ok(e) => e,
Err(err) => {
@@ -79,15 +80,18 @@ impl Files {
return;
}
};
let collected = paths.collect::<Vec<_>>();
log::info!("Path list reloaded {:#?}", collected);
// clear the current state
self.clear_err();
self.path_names.clear();
for path in paths {
for path in collected {
self.path_names
.push(path.unwrap().path().display().to_string());
}
log::info!("path namees are {:#?}", self.path_names);
}
fn go_up(&mut self) {
+1 -1
View File
@@ -30,7 +30,7 @@ fn main() {
AppendChildren { many: 1 },
];
dioxus_desktop::WebviewRenderer::run_with_edits(APP, (), |c| c, Some(edits)).expect("failed");
dioxus_desktop::run(APP, (), |c| c.with_edits(edits)).unwrap();
}
const APP: FC<()> = |cx, _props| {
+2 -2
View File
@@ -16,7 +16,7 @@
//! RefMuts at the same time.
use dioxus::desktop::wry::application::dpi::LogicalSize;
use dioxus::events::on::*;
use dioxus::events::{on::*, KeyCode};
use dioxus::prelude::*;
const STYLE: &str = include_str!("./assets/calculator.css");
@@ -169,7 +169,7 @@ impl Calculator {
self.waiting_for_operand = true;
}
fn handle_keydown(&mut self, evt: KeyboardEvent) {
match evt.key_code() {
match evt.key_code {
KeyCode::Backspace => self.backspace(),
KeyCode::Num0 => self.input_digit(0),
KeyCode::Num1 => self.input_digit(1),
+2 -2
View File
@@ -57,7 +57,7 @@ const App: FC<()> = |cx, props| {
class: "new-todo"
placeholder: "What needs to be done?"
value: "{draft}"
oninput: move |evt| draft.set(evt.value())
oninput: move |evt| draft.set(evt.value.clone())
}
}
{todolist}
@@ -100,7 +100,7 @@ pub fn TodoEntry<'a>(cx: Context<'a>, props: &TodoEntryProps) -> DomTree<'a> {
{is_editing.then(|| rsx!{
input {
value: "{contents}"
oninput: move |evt| contents.set(evt.value())
oninput: move |evt| contents.set(evt.value.clone())
}
})}
})