Make benches compile

This commit is contained in:
Jonathan Kelley committed 2024-01-30 18:29:49 -08:00
1 parent 09e14f1936
commit 69f9bb6b65
9 files changed
+60 -62

No files matched your search

+4 -2
View File
@@ -25,7 +25,7 @@ fn main() {
}
/// We only have one list of clients for the whole app, so we can use a global signal.
static CLIENTS: GlobalSignal<Vec<Client>> = Signal::global(|| Vec::new());
static CLIENTS: GlobalSignal<Vec<Client>> = Signal::global(Vec::new);
struct Client {
first_name: String,
@@ -93,7 +93,9 @@ fn ClientAdd() -> Element {
oninput: move |e| first_name.set(e.value()),
// when the form mounts, focus the first name input
onmounted: move |e| {e.inner().set_focus(true);},
onmounted: move |e| async move {
_ = e.inner().set_focus(true).await;
},
}
}
+1 -1
View File
@@ -6,7 +6,7 @@ fn main() {
fn app() -> Element {
let mut value = use_signal(|| 0);
let mut depth = use_signal(|| 0 as usize);
let mut depth = use_signal(|| 0_usize);
let items = use_memo(move || (0..depth()).map(|f| f as _).collect::<Vec<isize>>());
let state = use_memo(move || value() + 1);
+1 -1
View File
@@ -6,7 +6,7 @@ fn main() {
fn app() -> Element {
let mut state = use_signal(|| 0);
let mut depth = use_signal(|| 1 as usize);
let mut depth = use_signal(|| 1_usize);
if depth() == 5 {
return rsx! {
+1 -1
View File
@@ -24,7 +24,7 @@ struct TodoItem {
const STYLE: &str = include_str!("./assets/todomvc.css");
fn app() -> Element {
let mut todos = use_signal(|| HashMap::<u32, TodoItem>::new());
let mut todos = use_signal(HashMap::<u32, TodoItem>::new);
let filter = use_signal(|| FilterState::All);
let active_todo_count =
+6 -4
View File
@@ -13,12 +13,14 @@ fn main() {
fn app() -> Element {
let mut focused = use_signal(|| true);
use_wry_event_handler(move |event, _| match event {
WryEvent::WindowEvent {
use_wry_event_handler(move |event, _| {
if let WryEvent::WindowEvent {
event: WindowEvent::Focused(new_focused),
..
} => focused.set(*new_focused),
_ => {}
} = event
{
focused.set(*new_focused)
}
});
rsx! {
+33 -43
View File
@@ -57,7 +57,7 @@ fn tui_update(c: &mut Criterion) {
}
}
#[derive(Props, PartialEq)]
#[derive(Props, PartialEq, Clone)]
struct BoxProps {
x: usize,
y: usize,
@@ -65,15 +65,15 @@ struct BoxProps {
alpha: f32,
}
#[allow(non_snake_case)]
fn Box(cx: ScopeState<BoxProps>) -> Element {
fn Box(props: BoxProps) -> Element {
let count = use_signal(|| 0);
let x = cx.props.x * 2;
let y = cx.props.y * 2;
let hue = cx.props.hue;
let display_hue = cx.props.hue as u32 / 10;
let count = count.get();
let alpha = cx.props.alpha + (count % 100) as f32;
let x = props.x * 2;
let y = props.y * 2;
let hue = props.hue;
let display_hue = props.hue as u32 / 10;
let count = count();
let alpha = props.alpha + (count % 100) as f32;
rsx! {
div {
@@ -88,24 +88,24 @@ fn Box(cx: ScopeState<BoxProps>) -> Element {
}
}
#[derive(Props, PartialEq)]
#[derive(Props, PartialEq, Clone)]
struct GridProps {
size: usize,
update_count: usize,
}
#[allow(non_snake_case)]
fn Grid(cx: ScopeState<GridProps>) -> Element {
let size = cx.props.size;
let count = use_signal(|| 0);
let counts = use_signal(|| vec![0; size * size]);
fn Grid(props: GridProps) -> Element {
let size = props.size;
let mut count = use_signal(|| 0);
let mut counts = use_signal(|| vec![0; size * size]);
let ctx: TuiContext = cx.consume_context().unwrap();
if *count.get() + cx.props.update_count >= (size * size) {
let ctx: TuiContext = consume_context();
if count() + props.update_count >= (size * size) {
ctx.quit();
} else {
for _ in 0..cx.props.update_count {
for _ in 0..props.update_count {
counts.with_mut(|c| {
let i = *count.current();
let i = count();
c[i] += 1;
c[i] %= 360;
});
@@ -121,44 +121,34 @@ fn Grid(cx: ScopeState<GridProps>) -> Element {
width: "100%",
height: "100%",
flex_direction: "column",
(0..size).map(|x|
{
rsx! {
div{
width: "100%",
height: "100%",
flex_direction: "row",
(0..size).map(|y|
{
let alpha = y as f32*100.0/size as f32 + counts.read()[x*size + y] as f32;
let key = format!("{}-{}", x, y);
rsx! {
Box{
x: x,
y: y,
alpha: 100.0,
hue: alpha,
key: "{key}",
}
}
}
)
for x in 0..size {
div {
width: "100%",
height: "100%",
flex_direction: "row",
for y in 0..size {
Box {
key: "{x}-{y}",
x: x,
y: y,
alpha: 100.0,
hue: y as f32*100.0/size as f32 + counts.read()[x*size + y] as f32,
}
}
}
)
}
}
}
}
fn app(cx: ScopeState<GridProps>) -> Element {
fn app(props: GridProps) -> Element {
rsx! {
div{
width: "100%",
height: "100%",
Grid{
size: cx.props.size,
update_count: cx.props.update_count,
size: props.size,
update_count: props.update_count,
}
}
}
+4
View File
@@ -29,6 +29,10 @@ pub fn launch_cfg(app: fn() -> Element, cfg: Config) {
launch_vdom_cfg(VirtualDom::new(app), cfg)
}
pub fn launch_cfg_with_props<P: Clone + 'static>(app: fn(P) -> Element, props: P, cfg: Config) {
launch_vdom_cfg(VirtualDom::new_with_props(app, props), cfg)
}
pub fn launch_vdom_cfg(vdom: VirtualDom, cfg: Config) {
dioxus_html::set_event_converter(Box::new(events::SerializedHtmlEventConverter));
+9 -9
View File
@@ -34,7 +34,7 @@ fn key_down() {
fn app() -> Element {
let render_count = use_signal(|| 0);
let mut render_count_handle = render_count.clone();
let mut render_count_handle = render_count;
let tui_ctx: TuiContext = consume_context();
spawn(async move {
@@ -77,7 +77,7 @@ fn mouse_down() {
fn app() -> Element {
let render_count = use_signal(|| 0);
let tui_ctx: TuiContext = consume_context();
let mut render_count_handle = render_count.clone();
let mut render_count_handle = render_count;
spawn(async move {
PollN::new(2).await;
render_count_handle.with_mut(|x| *x + 1);
@@ -113,7 +113,7 @@ fn mouse_up() {
fn app() -> Element {
let render_count = use_signal(|| 0);
let tui_ctx: TuiContext = consume_context();
let mut render_count_handle = render_count.clone();
let mut render_count_handle = render_count;
spawn(async move {
PollN::new(3).await;
render_count_handle.with_mut(|x| *x + 1);
@@ -151,7 +151,7 @@ fn mouse_enter() {
fn app() -> Element {
let render_count = use_signal(|| 0);
let mut render_count_handle = render_count.clone();
let mut render_count_handle = render_count;
let tui_ctx: TuiContext = consume_context();
spawn(async move {
PollN::new(3).await;
@@ -191,7 +191,7 @@ fn mouse_exit() {
fn app() -> Element {
let render_count = use_signal(|| 0);
let tui_ctx: TuiContext = consume_context();
let mut render_count_handle = render_count.clone();
let mut render_count_handle = render_count;
spawn(async move {
PollN::new(3).await;
render_count_handle.with_mut(|x| *x + 1);
@@ -230,7 +230,7 @@ fn mouse_move() {
fn app() -> Element {
let render_count = use_signal(|| 0);
let tui_ctx: TuiContext = consume_context();
let mut render_count_handle = render_count.clone();
let mut render_count_handle = render_count;
spawn(async move {
PollN::new(3).await;
render_count_handle.with_mut(|x| *x + 1);
@@ -269,7 +269,7 @@ fn wheel() {
fn app() -> Element {
let render_count = use_signal(|| 0);
let tui_ctx: TuiContext = consume_context();
let mut render_count_handle = render_count.clone();
let mut render_count_handle = render_count;
spawn(async move {
PollN::new(3).await;
render_count_handle.with_mut(|x| *x + 1);
@@ -309,7 +309,7 @@ fn click() {
fn app() -> Element {
let render_count = use_signal(|| 0);
let tui_ctx: TuiContext = consume_context();
let mut render_count_handle = render_count.clone();
let mut render_count_handle = render_count;
spawn(async move {
PollN::new(3).await;
render_count_handle.with_mut(|x| *x + 1);
@@ -348,7 +348,7 @@ fn context_menu() {
fn app() -> Element {
let render_count = use_signal(|| 0);
let tui_ctx: TuiContext = consume_context();
let mut render_count_handle = render_count.clone();
let mut render_count_handle = render_count;
spawn(async move {
PollN::new(3).await;
render_count_handle.with_mut(|x| *x + 1);
+1 -1
View File
@@ -1,5 +1,5 @@
//! Launch helper macros for fullstack apps
#![allow(clippy::new_without_default)]
#![allow(unused)]
use std::any::Any;