Changelog History
Page 3
-
v0.11 Changes
January 06, 2020๐ This release aims to lay the groundwork for Yew component libraries and clean up the API for the ever elusive 1.0 release.
Transition Guide
๐ This release comes with a lot of breaking changes. We understand it's a hassle to update projects but the Yew team felt it was necessary to rip a few bandaids off now as we approach a 1.0 release in the (hopefully) near future. To ease the transition, here's a guide which outlines the main refactoring you will need to do for your project. (Note: all of the changes are reflected in the many example projects if you would like a proper reference example)
1. Callback syntax
This is the main painful breaking change. It applies to both element listeners as well as
Component
callback properties. A good rule of thumb is that your components will now have to retain aComponentLink
to create callbacks on demand or initialize callbacks in your component'screate()
method.Before:
struct MyComponent; enum Msg { Click, } impl Component for MyComponent { type Message = Msg; type Properties = (); fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self { MyComponent } fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { Msg::Click => true, } } fn view(&self) -> Html<Self> { // BEFORE: Callbacks were created implicitly from this closure syntax html! { <button onclick=|_| Msg::Click>{ "Click me!" }</button> } } }
After:
struct MyComponent { link: ComponentLink<Self>, } enum Msg { Click, } impl Component for MyComponent { type Message = Msg; type Properties = (); fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self { MyComponent { link } } fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { Msg::Click => true, } } fn view(&self) -> Html { // AFTER: Callbacks need to be explicitly created now let onclick = self.link.callback(|_| Msg::Click); html! { <button onclick=onclick>{ "Click me!" }</button> } } }
If a closure has a parameter you will now need to specify the parameter's type. A tip for finding the appropriate type is to search Yew's repo for the HTML attribute the closure is assigned to.
For example,
onkeydown
of<button>
:let onkeydown = self.link.callback(|e: KeyDownEvent| { // ... });
and
html! { <button onkeydown=onkeydown type="button"> { "button" } </button> }
2. Method Renames
It should be safe to do a project-wide find/replace for the following:
send_self(
->send_message(
send_back(
->callback(
response(
->respond(
- โก๏ธ
AgentUpdate
->AgentLifecycleEvent
These renames will probably require some more care:
fn handle(
->fn handle_input(
(for Agent trait implementations)
3. Drop Generic Types for
Html<Self>
->Html
:tada: We are pretty excited about this change! The generic type parameter was confusing and restrictive and is now a thing of the past!
Before:
impl Component for MyComponent { // ... fn view(&self) -> Html<Self> { html! { /* ... */ } } }
After:
impl Component for MyComponent { // ... fn view(&self) -> Html { html! { /* ... */ } } }
๐ฏ 4. Properties must implement
Clone
๐ In yew v0.8 we removed the requirement that component properties implement
Clone
๐ and in this release we are adding the requirement again. This change is needed to improve the ergonomics of nested components. The only time properties will be ๐ฏ cloned is when a wrapper component re-renders nested children components.โก๏ธ Features
- Added
html_nested!
macro to support nested iterable children access. [[@trivigy], #843] - Added
bincode
to the list of supported formats. [[@serzhiio], #806] - Added a
noop()
convenience method toCallback
which creates a no-op callback. [[@mdtusz], #793] - The
html!
macro now accepts aCallback
for element listeners. [[@jstarry], #777]
- Added
struct MyComponent { onclick: Callback<ClickEvent>, } enum Msg { Click, } impl Component for MyComponent { type Message = Msg; type Properties = (); fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self { MyComponent { onclick: link.callback(|_| Msg::Click), } } fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { Msg::Click => true, } } fn view(&self) -> Html { html! { <button onclick=&self.onclick>{ "Click me!" }</button> } } }
- Add
send_message_batch
method toComponentLink
. [[@hgzimmerman], #748] - Allow compilation to
wasi
target withoutwasm_bindgen
. [[@dunnock], #746] AgentLink
now implementsClone
which enablesFuture
usage without explicit Yew framework support. [[@izissise], #802]ComponentLink
now implementsClone
which enablesFuture
usage without explicit Yew framework support. [[@hgzimmerman], #749]
use wasm_bindgen::JsValue; use wasm_bindgen_futures::future_to_promise; // future must implement `Future<Output = Component::Message> + 'static` let link = self.link.clone(); let js_future = async move { link.send_message(future.await); Ok(JsValue::NULL) }; future_to_promise(js_future);
๐ #### ๐ Fixes
fn view(&self) -> Html { html! { <Wrapper> // This is now valid. (before #780, this would cause a lifetime // compile error because children nodes were moved into a closure) <Nested on_click=&self.nested_on_click /> </Wrapper> } }
- Creating a
Callback
withComponentLink
is no longer restricted to mutable references, improving ergonomics. [[@jstarry], #780] - The
Callback
reform
method no longer consumes self making it easier to "reverse map" aCallback
. [[@jstarry], #779]
pub struct ListHeader { props: Props, } #[derive(Properties, Clone)] pub struct Props { #[props(required)] pub on_hover: Callback<Hovered>, #[props(required)] pub text: String, } impl Component for ListHeader { type Message = (); type Properties = Props; fn create(props: Self::Properties, _: ComponentLink<Self>) -> Self { ListHeader { props } } fn update(&mut self, _: Self::Message) -> ShouldRender { false } fn view(&self) -> Html { let onmouseover = self.props.on_hover.reform(|_| Hovered::Header); html! { <div class="list-header" onmouseover=onmouseover> { &self.props.text } </div> } } }
- Reduced allocations in the
Classes
to_string
method. [[@hgzimmerman], #772] Empty string class names are now filtered out to prevent panics. [[@jstarry], #770]
- #### ๐จ Breaking changes
Components with generic args now need to be closed with the full type path. (e.g.
html! { <Wrapper<String>></Wrapper<String>>}
) [[@jstarry], #837]Changed
VTag
listener type fromBox<dyn Listener>
toRc<dyn Listener>
. [[@jstarry], #786]Properties
need to implementClone
again in order to improve nested component ergonomics. [[@jstarry], #786]Removed
send_future
method fromComponentLink
since it is no longer necessary for using Futures with Yew. [[@hgzimmerman], #799]Removed generic type parameter from
Html
and all virtual node types:VNode
,VComp
,VTag
,VList
,VText
, etc. [[@jstarry], #783]Removed support for macro magic closure syntax for element listeners. (See transition guide for how to pass a
Callback
explicitly instead). [[@jstarry], #782]Renamed
Agent
methods and event type for clarity.handle
->handle_input
,AgentUpdate
->AgentLifecycleEvent
,response
->respond
. [[@philip-peterson], #751]The
ComponentLink
send_back
method has been renamed tocallback
for clarity. [[@jstarry], #780]The
ComponentLink
send_self
andsend_self_batch
methods have been renamed tosend_message
andsend_message_batch
for clarity. [[@jstarry], #780]The
Agent
send_back
method has been renamed tocallback
for clarity. [[@jstarry], #780]The
VTag
children
value type has changed fromVec<VNode>
toVList
. [[@jstarry], #754]
-
v0.10 Changes
November 11, 2019โก๏ธ Features
Future
support :tada: AComponent
can update following the completion of aFuture
. Check out this example to see how it works. This approach was borrowed from a fork of Yew calledplaster
created by [@carlosdp]. [[@hgzimmerman], #717]- Added the
agent
andservices
features so that this functionality can be disabled (useful if you are switching to usingFuture
s). [[@hgzimmerman], #684] - Add
ref
keyword for allowing aComponent
to have a direct reference to its rendered elements. For example, you can now easily focus an<input>
element after mounting. [[@jstarry], #715]
use stdweb::web::html_element::InputElement; use stdweb::web::IHtmlElement; use yew::prelude::*; pub struct Input { node_ref: NodeRef, } impl Component for Input { type Message = (); type Properties = (); fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self { Input { node_ref: NodeRef::default(), } } fn mounted(&mut self) -> ShouldRender { if let Some(input) = self.node_ref.try_into::<InputElement>() { input.focus(); } false } fn update(&mut self, _: Self::Message) -> ShouldRender { false } fn view(&self) -> Html<Self> { html! { <input ref=self.node_ref.clone() type="text" /> } } }
- Make
Agent
related typespublic
to allow other crates to create custom agents. [[@dunnock], #721] Component::change
will now returnfalse
for components that haveComponent::Properties == ()
. [[@kellytk], #690]]Updated
wasm-bindgen
dependency to0.2.54
. Please update yourwasm-bindgen-cli
tool by runningcargo install --force --version 0.2.54 -- wasm-bindgen-cli
. [[@jstarry], #730], [[@ctaggart], #681]- ๐ #### ๐ Fixes
Fixed the mount order of components. The root component will be mounted after all descendants have been mounted. [[@jstarry], #725]
All public items now implement
Debug
. [[@hgzimmerman], #673]- #### ๐จ Breaking changes
Minimum rustc version has been bumped to
1.39.0
forFuture
support. [[@jstarry], #730]Component
now has a requiredview
method and automatically implements theRenderable
trait. Theview
method in theRenderable
trait has been renamed torender
. [[@jstarry], #563]Before:
impl Component for MyComponent { type Message = Msg; type Properties = (); fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self { MyComponent {} } fn update(&mut self, msg: Self::Message) -> ShouldRender { true } } impl Renderable<MyComponent> for MyComponent { fn view(&self) -> Html<Self> { html! { "hello" } } }
After:
impl Component for MyComponent { type Message = Msg; type Properties = (); fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self { MyComponent {} } fn update(&mut self, msg: Self::Message) -> ShouldRender { true } fn view(&self) -> Html<Self> { html! { "hello" } } }
Removed the
Transferable
trait since it did no more than extend the serdeSerialize
andDeserialize
traits. [[@hgzimmerman], #319]Before:
impl Transferable for Input {} #[derive(Serialize, Deserialize)] pub enum Input { Connect, }
After:
#[derive(Serialize, Deserialize)] pub enum Input { Connect, }
WebSocketService::connect
will now return aResult
in order to stop panicking on malformed urls. [[@lizhaoxian], #727]VTag
now is boxed withinVNode
to shrink the size of its enum representation. [[@hgzimmerman], #675]
-
v0.9.2 Changes
October 12, 2019๐ #### ๐ Fixes
- Fix
yew-macro
dependency version
- Fix
-
v0.9.1 Changes
October 12, 2019Happy Canadian Thanksgiving! ๐ฆ
โก๏ธ Features
- Implemented
Default
trait forVNode
so thatunwrap_or_default
can be called onOption<Html<Self>>
. [[@hgzimmerman], #672] - Implemented
PartialEq
trait forClasses
so that is more ergonomic to useClasses
type in component props. [[@hgzimmerman], #680] - Updated
wasm-bindgen
dependency to0.2.50
. Please update yourwasm-bindgen-cli
tool by runningcargo install --force --version 0.2.50 -- wasm-bindgen-cli
. [[@jstarry], #695]
- Implemented
๐ #### ๐ Fixes
- Fixed issue where text nodes were sometimes rendered out of order. [[@jstarry], #697]
- Fixed regression introduced in 0.9.0 that prevented tag attributes from updating properly. [[@jstarry], #698]
- Fixed emscripten builds by pinning the version for the
ryu
downstream dependency. [[@jstarry], #703] - Updated
stdweb
to0.4.20
which fixed emscripten builds and unblocked updatingwasm-bindgen
to0.2.50
. [[@ctaggart], [@jstarry], #683, #694] - Cleaned up build warnings for missing
dyn
keywords. [[@benreyn], #687]
-
v0.9 Changes
September 27, 2019โก๏ธ Features
- New
KeyboardService
for setting up key listeners on browsers which support the feature. [[@hgzimmerman], #647] ComponentLink
can now create aCallback
with more than oneMessage
. TheMessage
's will be batched together so that theComponent
will not be re-rendered more than necessary. [[@stkevintan], #660]Message
's toPublic
Agent
's will now be queued if theAgent
hasn't finished setting up yet. [[@serzhiio], #596]Agent
's can now be connected to without aCallback
. Instead of creating a bridge to the agent, create a dispatcher like so:MyAgent::dispatcher()
. [[@hgzimmerman], #639]Component
's can now accept children in thehtml!
macro. [[@jstarry], #589]
// app.rs html! { <MyList name="Grocery List"> <MyListItem text="Apples" /> </MyList> }
// my_list.rs use yew::prelude::*; pub struct MyList(Props); #[derive(Properties)] pub struct Props { #[props(required)] pub name: String, pub children: Children<MyListItem>, } impl Renderable<MyList> for MyList { fn view(&self) -> Html<Self> { html! {{ self.props.children.iter().collect::<Html<Self>>() }} } }
Iterator
s can now be rendered in thehtml!
macro without using thefor
keyword. [[@hgzimmerman], #622]
Before:
html! {{ for self.props.items.iter().map(renderItem) }}
After:
html! {{ self.props.items.iter().map(renderItem).collect::<Html<Self>>() }}
- Closures are now able to be transformed into optional
Callback
properties. [[@Wodann], #612] - Improved CSS class ergonomics with new
Classes
type. [[@DenisKolodin], #585], [[@hgzimmerman], #626] - Touch events are now supported
<div ontouchstart=|_| Msg::TouchStart>
[[@boydjohnson], #584], [[@jstarry], #656] - The
Component
trait now has anmounted
method which can be implemented to react to when your components have been mounted to the DOM. [[@hgzimmerman], #583] - Additional Fetch options
mode
,cache
, andredirect
are now supported [[@davidkna], #579] - The derive props macro now supports Properties with lifetimes [[@jstarry], #580]
- New
ResizeService
for registering forwindow
size updates [[@hgzimmerman], #577]
- New
๐ #### ๐ Fixes
- Fixed JS typo in RenderService. This was causing animation frames to not be dropped correctly. [[@jstarry], #658]
- Fixed
VNode
orphaning bug when destroyingVTag
elements. This caused someComponent
s to not be properly destroyed when they should have been. [[@hgzimmerman], #651] - Fix mishandling of Properties
where
clause in derive_props macro [[@astraw], #640]
๐จ Breaking changes
None
-
v0.8.1 Changes
January 10, 2020- ๐ #### ๐ Fixes
- Fixed a dependency issue with
wasm-bindgen
that would cause builds to fail when building for thewasm32-unknown-unknown
target.
- Fixed a dependency issue with
- ๐ #### ๐ Fixes
-
v0.8 Changes
August 10, 2019Props! Props! Props!
๐ This release introduces a more developer friendly way to handle your
Component
props. Use the new#[derive(Properties)]
macro to beef up your props! Property values can now be annotated as#[props(required)]
which will enforce that props are present at compile time. This means that your props struct no longer needs to implementDefault
, so time to clean up all of those prop values you wrapped inOption
to have a default value.โก๏ธ Features
html!
- Self-closing html tags can now be used:<div class="marker" />
[[@totorigolo], #523]html!
- SVG name-spaced tags are now supported! [[@jstarry], #550]- Properties can now be required at compile time [[@jstarry], #553]
- App components can now be mounted with properties [[@jstarry], #567]
- Apps can now be mounted as the
<body>
tag [[@jstarry], [@kellytk], #540] - Content editable elements can now trigger
oninput
events [[@tiziano88], #549]
๐ #### ๐ Fixes
html!
- Class name order is now preserved which unlocks the use of Semantic UI [[@charvp], #424]html!
- Dashed tag names and properties are supported [[@jstarry], #512, #550]html!
- All rust keywords can be used as tag attributes [[@jstarry], #550]html!
- SupportCallback
closure with explicit return type [[@totorigolo], #564]html!
- Fixed edge case where>
token would break parser [[@totorigolo], #565]- Performance improvement to the diff engine [[@totorigolo], #539]
Properties
no longer need to implement thePartialEq
,Clone
, orDefault
traits [[@jstarry], #553]Component
will not panic if thechange
method is unimplemented [[@jstarry], #554]
๐จ Breaking changes
- The
Component::Properties
associated type must implement the newProperties
trait [[@jstarry], #553]
The new
Properties
trait is what powers the ability to check required props are present at compile time. Use the derive props macro to implement automatically.use yew::Properties; #[derive(Properties)] pub struct Props { #[props(required)] pub value: MyStruct, }
Callback
props no longer transform intoOption
types [[@jstarry], #553]
html! { <Button on_click=Msg::Click /> }
before:
#[derive(PartialEq, Clone, Default)] pub struct Props { on_click: Option<Callback<()>>, }
after: note the
#[props(required)]
attribute#[derive(PartialEq, Properties)] pub struct Props { #[props(required)] on_click: Callback<()>, }
- The
-
v0.7 Changes
July 19, 2019Commas? We don't need no stinkin' commas!
๐ This release brings a new and improved
html!
macro for writing JSX-like syntax. Commas and colons are no longer necessary now that the macro is written as a procedural macro.โก๏ธ Features
๐ #### ๐ Fixes
html!
- Commas are no longer necessary for splitting up attributes [[@jstarry], #500]html!
- Colons are no longer necessary for denoting aComponent
tag [[@jstarry], #500]- Textarea value can be now be set:
<textarea value="content">
[[@DenisKolodin], #476] - changed
StorageService::restore
to take an immutable receiver [[@dermetfan], #480] - Fixed a component rendering bug [[@jstarry], #502]
-
v0.6.1 Changes
November 01, 2019- #### โก๏ธ Features
- Bring back
{}
,{*}
, and{<number>}
capture syntax for tuple structs/enum variants. If your variant or struct doesn't have named fields, you don't need to supply names in the matcher string [116] - Allow ! special character in more places.
- Greatly improve the quality of matcher string parsing errors. [171]
- Add
impl<SW: Switch, T> From<SW> for Route<T>
. Now Routes can be created from Switches easily. - Allow escaping {, }, and ! special characters by using
{{
,}}
, and!!
respectively. - Provide a correct error message when attempting to derive
Switch
for a Unit struct/variant with a capture group.
- Bring back
- #### โก๏ธ Features
-
v0.6 Changes
February 20, 2019โก๏ธ Features
- Added
start_app
convenience method for initializing the app and mounting it to the body [[@DenisKolodin], #462] - Added handling of files of
input
element. There is now aChangeData::Files
variant for theonchange
handler [[@DenisKolodin], #464] - Added
ReaderService
to read data fromFile
instances. [[@DenisKolodin], #464, #468]
- Added
๐ #### ๐ Fixes
- It was impossible to set
value
attribute for any tag instead ofoption
, because it used inner value ofVTag
to keep the value forinput
element. Nowvalue
attribute works foroptions
,progress
tags, etc.
- It was impossible to set
๐ฎ Examples
- New example
file_upload
that prints sizes of uploaded files [[@DenisKolodin], #464]
- New example