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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use Rc;
use *;
use *;
use crateBounceRootState;
/// A trait to apply a notion on a state.
///
/// See: [`use_notion_applier`](crate::use_notion_applier)
/// A hook to create a function that applies a `Notion`.
///
/// A `Notion` is an action that can be dispatched to any state that accepts the dispatched notion.
///
/// Any type that is `'static` can be dispatched as a notion.
///
/// Returns `Rc<dyn Fn(T)>`.
///
/// # Note
///
/// When states receives a notion, it will be wrapped in an `Rc<T>`.
///
/// # Example
///
/// ```
/// # use bounce::prelude::*;
/// # use std::fmt;
/// # use std::rc::Rc;
/// # use yew::prelude::*;
/// # use bounce::prelude::*;
/// pub struct Reset;
///
/// #[derive(PartialEq, Atom)]
/// #[bounce(with_notion(Reset))] // A #[bounce(with_notion(Notion))] needs to be denoted for the notion.
/// struct Username {
/// inner: String,
/// }
///
/// // A WithNotion<T> is required for each notion denoted in the #[bounce(with_notion)] attribute.
/// impl WithNotion<Reset> for Username {
/// fn apply(self: Rc<Self>, _notion: Rc<Reset>) -> Rc<Self> {
/// Self::default().into()
/// }
/// }
///
/// // second state
/// #[derive(PartialEq, Atom, Default)]
/// #[bounce(with_notion(Reset))]
/// struct Session {
/// token: Option<String>,
/// }
///
/// impl WithNotion<Reset> for Session {
/// fn apply(self: Rc<Self>, _notion: Rc<Reset>) -> Rc<Self> {
/// Self::default().into()
/// }
/// }
/// #
/// # impl Default for Username {
/// # fn default() -> Self {
/// # Self {
/// # inner: "Jane Doe".into(),
/// # }
/// # }
/// # }
/// #
/// # #[function_component(Setter)]
/// # fn setter() -> Html {
/// let reset_everything = use_notion_applier::<Reset>();
/// reset_everything(Reset);
/// # Html::default()
/// # }
/// ```