fix: Icon returns the function's warning (#127)

This commit is contained in:
luoxiaozero 2024-03-03 17:17:25 +08:00 committed by GitHub
parent 4d0adf61ac
commit 1a55b45d01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -38,9 +38,9 @@ pub fn Icon(
let icon = icon.get();
let style = match (style.clone(), icon.style) {
(Some(a), Some(b)) => Some((move || format!("{b} {}", a.get())).into_attribute()),
(Some(a), None) => Some((move || a.get()).into_attribute()),
(None, Some(b)) => Some(b.into_attribute()),
(Some(a), Some(b)) => Some(Memo::new(move |_| format!("{b} {}", a.get())).into()),
(Some(a), None) => Some(a),
(None, Some(b)) => Some(b.into()),
(None, None) => None,
};
icon_style.set(style);
@ -49,14 +49,14 @@ pub fn Icon(
icon_y.set(icon.y.map(|y| y.into_attribute()));
let width = match (width.clone(), icon.width) {
(Some(a), _) => (move || a.get()).into_attribute(),
_ => "1em".into_attribute(),
(Some(a), _) => a,
_ => "1em".into(),
};
icon_width.set(Some(width));
let height = match (height.clone(), icon.height) {
(Some(a), _) => (move || a.get()).into_attribute(),
_ => "1em".into_attribute(),
(Some(a), _) => a,
_ => "1em".into(),
};
icon_height.set(Some(height));
@ -72,11 +72,11 @@ pub fn Icon(
view! {
<svg
class=class.map(|c| c.get())
style=move || take(icon_style)
style=move || take_signal(icon_style)
x=move || take(icon_x)
y=move || take(icon_y)
width=move || take(icon_width)
height=move || take(icon_height)
width=move || take_signal(icon_width)
height=move || take_signal(icon_height)
viewBox=move || take(icon_view_box)
stroke-linecap=move || take(icon_stroke_linecap)
stroke-linejoin=move || take(icon_stroke_linejoin)
@ -88,6 +88,14 @@ pub fn Icon(
}
}
fn take_signal(signal: RwSignal<Option<MaybeSignal<String>>>) -> Option<String> {
signal.with(|s| match s {
Some(MaybeSignal::Static(value)) => Some(value.clone()),
Some(MaybeSignal::Dynamic(signal)) => Some(signal.get()),
_ => None,
})
}
fn take(signal: RwSignal<Option<Attribute>>) -> Option<Attribute> {
signal.track();
signal.try_update_untracked(|value| value.take()).flatten()