1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Shortcut for terse component definitions.
use crateNeqAssign;
use ;
/// Allows immutable components to be declared using a single struct and a single method.
/// Wrapper component for pure components.
///
/// Due to constraints in Rust's coherence rules, `Component` can't be implemented for any `T` that implements
/// `PureComponent`, so instead this struct wraps a `T: PureComponent` and `Component` is implemented
/// for this instead.
///
/// # Example
///
/// ```
/// # use yew::{html, Callback, Html, MouseEvent, Properties};
/// use yewtil::{Pure, PureComponent};
///
/// /// Alias to improve usability.
/// pub type Button = Pure<PureButton>;
///
/// #[derive(Clone, PartialEq, Properties)]
/// pub struct PureButton {
/// pub callback: Callback<MouseEvent>,
/// #[prop_or_default]
/// pub text: String,
/// }
/// impl PureComponent for PureButton {
/// fn render(&self) -> Html {
/// html! {
/// <button onclick=&self.callback>{ &self.text }</button>
/// }
/// }
/// }
///
/// # fn view() -> Html {
/// // Pure components can be used like normal components
/// html! { <Button callback=Callback::from(|_| println!("clicked")) text="Click me!" /> }
/// # }
/// ```
;