This is mostly a bug-fix release with a few small features. There will probably be one or two more patch releases before 0.5.0
.
New Features
mut
in component props
This didn't work before; now it does:
#[component]
fn TestMutCallback<'a, F>(
cx: Scope,
mut callback: F,
value: &'a str,
) -> impl IntoView
where
F: FnMut(u32) + 'static,
{
MaybeProp
type
MaybeProp
is essentially a wrapper for Option<MaybeSignal<Option<T>>>
with a nicer API. This is useful for something like a component library, where you want to give a user the maximum flexibility in the types they give to props while still checking that they're the appropriate T
.
This allows you to define optional props that
- may or may not be provided
- if provided, may be a plain value or a signal
- if a signal type, may or may not have a value (i.e., are a
Signal<Option<T>>
)
Implementing
From<_>
for a plainSignal<T>
type here is possible, but depends on the changes in0.5.0
, so I'll add it for that release.
#[component]
pub fn App(cx: Scope) -> impl IntoView {
let (count, set_count) = create_signal(cx, 5);
view! { cx,
<TakesMaybeProp/>
<TakesMaybeProp maybe=42/>
<TakesMaybeProp maybe=Signal::derive(cx, move || Some(count.get()))/>
}
}
#[component]
pub fn TakesMaybeProp(cx: Scope, #[prop(optional, into)] maybe: MaybeProp<i32>) -> impl IntoView {
// .get() gives you `Option<T>`, replacing `self.as_ref().and_then(|n| n.get())`
let value: Option<i32> = maybe.get();
// .with() takes a plain `&T`; returns `None` if the prop isn't present or the inner value is None
let plus_one = maybe.with(|n: &i32| n + 1);
view! { cx,
<p>{maybe}</p>
}
}
What's Changed
- (doc)expand spawn_local documentation by @Bechma in #1433
- fix(examples): unable to parse makefile (#1440) by @agilarity in #1441
- fix: incorrect opening node for
<Each/>
in debug mode (closes #1168) by @gbj in #1436 - docs: fix typo in 23_ssr_modes.md by @gbj in #1445
- feat: add
MaybeProp
type by @gbj in #1443 - perf(examples): speed up the test-info report (#1446) by @agilarity in #1447
- feat: allow
mut
in component props and suppress "needless lifetime" warning (closes #1458) by @gbj in #1459 - fix:
AnimatedShow
- possible panic on cleanup by @sebadob in #1464 - Document the magic number 128 as FILTER_SHOW_COMMENT. by @martinfrances107 in #1468
- Update README.md by @randommm in #1470
- fix: properly replace text nodes in DynChild (closes #1456) by @gbj in #1472
- fix: compile-time regression for deeply-nested component trees by @gbj in #1476
- fix: correctly escape HTML in DynChild text nodes by @gbj in #1478
- Minor: doclink to Error needed FQDN. by @martinfrances107 in #1469
- Fix typo in docs for
ServerFnErrorErr
by @DanikVitek in #1477 - fix: correctly export all DOM helpers by @gbj in #1486
New Contributors
- @Bechma made their first contribution in #1433
- @randommm made their first contribution in #1470
- @DanikVitek made their first contribution in #1477
Full Changelog: v0.4.6...v.0.4.7