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
68
69
70
71
72
73
74
use ShouldRender;
/// Alternative to using Message enums.
///
/// Using Effects instead of Messages allows you to define the mutation to your component's state
/// from inside `html!` macros instead of from within update functions.
>);
/// Terser wrapper function to be used instead of `Effect::new()`.
///
/// # Example
///
/// ```
/// # use yew::prelude::*;
/// use yewtil::{effect, Effect};
///
/// pub struct Model {
/// link: ComponentLink<Self>,
/// value: bool,
/// }
/// impl Component for Model {
/// type Message = Effect<Self>;
/// # type Properties = ();
///
/// fn create(_props: Self::Properties, link: ComponentLink<Self>) -> Self {
/// Self { link, value: false }
/// }
///
/// fn update(&mut self, msg: Self::Message) -> ShouldRender {
/// msg.call(self)
/// }
/// #
/// # fn change(&mut self, _props: Self::Properties) -> ShouldRender {
/// # unimplemented!()
/// # }
///
/// fn view(&self) -> Html {
/// html! {
/// <>
/// <span>{ self.value }</span>
/// <button
/// onclick=self.link.callback(|_| effect(|model: &mut Self| {
/// model.value = !model.value;
/// true
/// }))
/// >
/// { "Toggle" }
/// </button>
/// </>
/// }
/// }
/// }
/// ```