fixed event names and removed superfluous debug stmt

This commit is contained in:
Jose Quesada 2022-12-05 12:23:53 -06:00
parent 589f2585cc
commit eba8af3b38
3 changed files with 19 additions and 23 deletions

View file

@ -83,19 +83,15 @@ fn view_fn(cx: Scope) -> impl IntoNode {
.dyn_child(move || text(count().to_string()))
.into_node(cx),
button(cx)
.on("click", move |_: web_sys::MouseEvent| {
set_tick.update(|t| *t += 1)
})
.on(ev::click, move |_| set_tick.update(|t| *t += 1))
.child(text("Tick"))
.into_node(cx),
button(cx)
.on("click", move |_: web_sys::Event| {
set_count.update(|n| *n += 1)
})
.on(ev::click, move |_| set_count.update(|n| *n += 1))
.child(text("Click me"))
.into_node(cx),
button(cx)
.on_delegated("click", move |_: web_sys::Event| {
.on(ev::Undelegated(ev::click), move |_| {
set_count.update(|n| *n += 1)
})
.child(text("Click me (delegated)"))
@ -133,7 +129,7 @@ struct MyComponent;
impl IntoNode for MyComponent {
fn into_node(self, cx: Scope) -> Node {
let component = Component::new("MyComponent", |cx| {
vec![[h2(cx).child(text("MyComponent"))].into_node(cx)]
h2(cx).child(text("MyComponent")).into_node(cx)
});
component.into_node(cx)

View file

@ -5,13 +5,13 @@ use itertools::{EitherOrBoth, Itertools};
use leptos_reactive::{create_effect, Scope};
use rustc_hash::FxHasher;
use smallvec::{smallvec, SmallVec};
use typed_builder::TypedBuilder;
use std::{
borrow::Cow,
cell::RefCell,
hash::{BuildHasherDefault, Hash},
rc::Rc,
};
use typed_builder::TypedBuilder;
use wasm_bindgen::JsCast;
type FxIndexSet<T> = indexmap::IndexSet<T, BuildHasherDefault<FxHasher>>;
@ -389,7 +389,7 @@ fn diff<K: Eq + Hash>(from: &FxIndexSet<K>, to: &FxIndexSet<K>) -> Diff {
}
}
normalized_idx = normalized_idx.wrapping_add(1);
normalized_idx = normalized_idx.wrapping_add(1);
}
let mut diffs = Diff {
@ -502,8 +502,6 @@ fn apply_cmds<T, EF, N>(
// we risk overwriting one of the values
let mut items_to_move = Vec::with_capacity(cmds.moved.len());
debug!("{cmds:#?}");
// The order of cmds needs to be:
// 1. Removed
// 2. Moved
@ -600,7 +598,6 @@ fn apply_cmds<T, EF, N>(
children.drain_filter(|c| c.is_none());
}
/// Properties for the [For](crate::For) component, a keyed list.
#[derive(TypedBuilder)]
pub struct ForProps<IF, I, T, EF, N, KF, K>
@ -613,12 +610,12 @@ where
K: Eq + Hash + 'static,
T: 'static,
{
/// Items over which the component should iterate.
pub each: IF,
/// A key function that will be applied to each item
pub key: KF,
/// Should provide a single child function, which takes
pub children: Box<dyn Fn() -> Vec<EF>>,
/// Items over which the component should iterate.
pub each: IF,
/// A key function that will be applied to each item
pub key: KF,
/// Should provide a single child function, which takes
pub children: Box<dyn Fn() -> Vec<EF>>,
}
/// Iterates over children and displays them, keyed by the `key` function given.
@ -661,7 +658,10 @@ where
/// }
/// ```
#[allow(non_snake_case)]
pub fn For<IF, I, T, EF, N, KF, K>(cx: Scope, props: ForProps<IF, I, T, EF, N, KF, K>) -> Node
pub fn For<IF, I, T, EF, N, KF, K>(
cx: Scope,
props: ForProps<IF, I, T, EF, N, KF, K>,
) -> Node
where
IF: Fn() -> I + 'static,
I: IntoIterator<Item = T>,
@ -673,4 +673,4 @@ where
{
let each_fn = (props.children)().swap_remove(0);
EachKey::new(props.each, props.key, each_fn).into_node(cx)
}
}

View file

@ -74,7 +74,7 @@ macro_rules! generate_event_types {
$(
#[doc = "The "]
#[doc = stringify!($event)]
#[doc = "event."]
#[doc = " event."]
#[allow(non_camel_case_types)]
pub struct $event;
@ -82,7 +82,7 @@ macro_rules! generate_event_types {
type EventType = web_sys::$web_sys_event;
fn name(&self) -> Cow<'static, str> {
stringify!([<$event:lower>]).into()
stringify!($event).into()
}
$(