mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
* remove ToHtml trait * re-add display impls * make Vec::clone expilit * fix doc * fix conflicting impls Into<Html> and Display can't be implemented on the same type * update docs * blanket impl won't work here * bring back `Vec<VNode>: IntoPropValue<VNode>` * macro tests * Revert "fix conflicting impls" This reverts commit 52f3c1fa8174489ba9cc783d708a49cc7b9c90a4. These impls are fine now * make examples compile * .clone() should be before .into() * Rc VList * Make use of ImplicitClone and AttrValue in example (There is more work to do but it's complicated so I will do it in another PR) * Impl ImplicitClone on VChild --------- Co-authored-by: Cecile Tonglet <cecile.tonglet@cecton.com>
78 lines
1.7 KiB
Rust
78 lines
1.7 KiB
Rust
mod app;
|
|
mod header;
|
|
mod item;
|
|
mod list;
|
|
|
|
use std::cell::RefCell;
|
|
use std::fmt;
|
|
use std::ops::Deref;
|
|
use std::rc::Rc;
|
|
|
|
use yew::html::{ImplicitClone, IntoPropValue, Scope};
|
|
use yew::prelude::*;
|
|
|
|
pub struct WeakComponentLink<COMP: Component>(Rc<RefCell<Option<Scope<COMP>>>>);
|
|
|
|
impl<COMP: Component> Clone for WeakComponentLink<COMP> {
|
|
fn clone(&self) -> Self {
|
|
Self(Rc::clone(&self.0))
|
|
}
|
|
}
|
|
impl<COMP: Component> ImplicitClone for WeakComponentLink<COMP> {}
|
|
|
|
impl<COMP: Component> Default for WeakComponentLink<COMP> {
|
|
fn default() -> Self {
|
|
Self(Rc::default())
|
|
}
|
|
}
|
|
|
|
impl<COMP: Component> Deref for WeakComponentLink<COMP> {
|
|
type Target = Rc<RefCell<Option<Scope<COMP>>>>;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl<COMP: Component> PartialEq for WeakComponentLink<COMP> {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
Rc::ptr_eq(&self.0, &other.0)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum Hovered {
|
|
Header,
|
|
Item(AttrValue),
|
|
List,
|
|
None,
|
|
}
|
|
|
|
impl ImplicitClone for Hovered {}
|
|
|
|
impl fmt::Display for Hovered {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
write!(
|
|
f,
|
|
"{}",
|
|
match self {
|
|
Hovered::Header => "Header",
|
|
Hovered::Item(name) => name,
|
|
Hovered::List => "List container",
|
|
Hovered::None => "Nothing",
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
impl IntoPropValue<Html> for &Hovered {
|
|
fn into_prop_value(self) -> Html {
|
|
html! {<>{self.to_string()}</>}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
wasm_logger::init(wasm_logger::Config::default());
|
|
yew::Renderer::<app::App>::new().render();
|
|
}
|