You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Until now, there was no way to ensure that a component would receive certain properties at compile time. Components were required to handle cases where properties were not set. Furthermore, the Properties associated type must implement the Default trait.
For example, if a component had a struct as a property, you were forced to pick a default value for it or wrap it in an Option:
This pattern forced a component to handle a default case that could have been avoided. Of course, you could always risk a runtime panic by using unwrap.
In yew 0.8, these workaround are no longer necessary since properties can be annotated as required. Yew will add a compile time guarantee that these props are present, avoiding the risk of a runtime panic. Properties must now implement the yew::Properties trait which can be derived with a macro like so:
use yew::Properties;#[derive(PartialEq,Properties)]pubstructProps{#[props(required)]pubgame_status:GameStatus,}
SVG support
It's now possible to render <svg> tags with Yew! This has been requested for a long time 😅. This change helped polish the html! {} macro as well since the SVG namespace uses a whole bunch of new attributes that need to be supported.
Dashed attribute and tag names are supported!
All rust keywords can now be used as attributes!
Here's a snippet of a complex svg image that works now with Yew:
There is a tracking issue for tracking benchmarking here: Performance details #5 which will be completed soon. Hoping that will unlock more opportunities for those who are interested in boosting yew's performance!
Component::Properties associated type must implement the new Properties trait
This change enables required properties and can be derived with #[derive(Properties)]. Additionally, the Clone + PartialEq + Default traits are no longer necessary but PartialEq is recommended for efficient updates.
use yew::Properties;#[derive(PartialEq,Properties)]pubstructProps{#[props(required)]pubgame_status:GameStatus,}
Required properties
Until now, there was no way to ensure that a component would receive certain properties at compile time. Components were required to handle cases where properties were not set. Furthermore, the
Properties
associated type must implement theDefault
trait.For example, if a component had a struct as a property, you were forced to pick a default value for it or wrap it in an
Option
:This pattern forced a component to handle a default case that could have been avoided. Of course, you could always risk a runtime panic by using
unwrap
.In yew 0.8, these workaround are no longer necessary since properties can be annotated as required. Yew will add a compile time guarantee that these props are present, avoiding the risk of a runtime panic. Properties must now implement the
yew::Properties
trait which can be derived with a macro like so:SVG support
It's now possible to render
<svg>
tags with Yew! This has been requested for a long time 😅. This change helped polish thehtml! {}
macro as well since the SVG namespace uses a whole bunch of new attributes that need to be supported.Here's a snippet of a complex svg image that works now with Yew:
Community Updates
Huge thanks to those who helped since the last release!
@totorigolo fixed self-closing tags html!: fix mixed self-closing and non-sc tags #523
It's now possible to write any tag as self-closing for brevity:
@tiziano88 added input event support for content editable elements Support inputevent listener for all elements #549
@totorigolo also submitted a perf improvement vdiff: remove unnecessary collect during diffing #539
There is a tracking issue for tracking benchmarking here: Performance details #5 which will be completed soon. Hoping that will unlock more opportunities for those who are interested in boosting yew's performance!
@charvp added persistent class ordering which unlocks frameworks like Semantic UI Preserve ordering of classes #424
@kellytk helped allow mounting directly to the
<body>
tag Allow mounting to the body tag #544Breaking changes
Component::Properties
associated type must implement the newProperties
traitThis change enables required properties and can be derived with
#[derive(Properties)]
. Additionally, theClone + PartialEq + Default
traits are no longer necessary butPartialEq
is recommended for efficient updates.Callbacks no longer transform into
Option
typesProps before:
Props after (note the props(required) attribute):
The text was updated successfully, but these errors were encountered: