bounce/lib.rs
1//! The uncomplicated Yew State management library.
2
3#![deny(clippy::all)]
4#![deny(missing_debug_implementations)]
5#![deny(unsafe_code)]
6#![deny(non_snake_case)]
7#![deny(clippy::cognitive_complexity)]
8#![deny(missing_docs)]
9#![cfg_attr(documenting, feature(doc_cfg))]
10#![cfg_attr(documenting, feature(doc_auto_cfg))]
11#![cfg_attr(any(releasing, not(debug_assertions)), deny(dead_code, unused_imports))]
12
13extern crate self as bounce;
14
15mod any_state;
16mod provider;
17mod root_state;
18mod states;
19mod utils;
20
21#[cfg_attr(documenting, doc(cfg(feature = "query")))]
22#[cfg(feature = "query")]
23pub mod query;
24
25#[cfg_attr(documenting, doc(cfg(feature = "helmet")))]
26#[cfg(feature = "helmet")]
27pub mod helmet;
28
29/// A simple state that is Copy-on-Write and notifies registered hooks when `prev_value != next_value`.
30///
31/// It can be derived for any state that implements [`PartialEq`] + [`Default`].
32///
33/// # Example
34///
35/// ```
36/// use std::rc::Rc;
37/// use bounce::prelude::*;
38/// use yew::prelude::*;
39///
40/// #[derive(PartialEq, Atom)]
41/// struct Username {
42/// inner: String,
43/// }
44///
45/// impl Default for Username {
46/// fn default() -> Self {
47/// Self {
48/// inner: "Jane Doe".into(),
49/// }
50/// }
51/// }
52/// ```
53/// See: [`use_atom`](crate::use_atom)
54pub use states::atom::Atom;
55
56/// A reducer-based state that is Copy-on-Write and notifies registered hooks when `prev_value != next_value`.
57///
58/// It can be derived for any state that implements [`Reducible`](yew::functional::Reducible) + [`PartialEq`] + [`Default`].
59///
60/// # Example
61///
62/// ```
63/// use std::rc::Rc;
64/// use bounce::prelude::*;
65/// use yew::prelude::*;
66///
67/// enum CounterAction {
68/// Increment,
69/// Decrement,
70/// }
71///
72/// #[derive(PartialEq, Default, Slice)]
73/// struct Counter(u64);
74///
75/// impl Reducible for Counter {
76/// type Action = CounterAction;
77///
78/// fn reduce(self: Rc<Self>, action: Self::Action) -> Rc<Self> {
79/// match action {
80/// CounterAction::Increment => Self(self.0 + 1).into(),
81/// CounterAction::Decrement => Self(self.0 - 1).into(),
82/// }
83/// }
84/// }
85/// ```
86/// See: [`use_slice`](crate::use_slice)
87pub use states::slice::Slice;
88
89/// A future-based notion that notifies states when it begins and finishes.
90///
91/// A future notion accepts a signle argument as input and returns an output.
92///
93/// It can optionally accept a `states` parameter which has a type of [`BounceStates`] that can be
94/// used to access bounce states when being run.
95///
96/// The async function must have a signature of either
97/// `Fn(&I) -> impl Future<Output = O>` or `Fn(&BounceState, &I) -> impl Future<Output = O>`.
98///
99/// Both `Input` and `Output` must live `'static`.
100///
101/// # Example
102///
103/// ```
104/// use std::rc::Rc;
105/// use bounce::prelude::*;
106/// use yew::prelude::*;
107///
108/// struct User {
109/// id: u64,
110/// name: String,
111/// }
112///
113/// #[future_notion(FetchData)]
114/// async fn fetch_user(id: &u64) -> User {
115/// // fetch user
116///
117/// User { id: *id, name: "John Smith".into() }
118/// }
119/// ```
120/// See: [`use_future_notion_runner`](crate::use_future_notion_runner)
121pub use bounce_macros::future_notion;
122
123pub use provider::{BounceRoot, BounceRootProps};
124pub use root_state::BounceStates;
125
126pub use states::artifact::{use_artifacts, Artifact, ArtifactProps};
127pub use states::atom::{use_atom, use_atom_setter, use_atom_value, CloneAtom, UseAtomHandle};
128pub use states::future_notion::{use_future_notion_runner, Deferred, FutureNotion};
129pub use states::input_selector::{use_input_selector_value, InputSelector};
130pub use states::notion::{use_notion_applier, WithNotion};
131pub use states::observer::Observed;
132pub use states::selector::{use_selector_value, Selector};
133pub use states::slice::{
134 use_slice, use_slice_dispatch, use_slice_value, CloneSlice, UseSliceHandle,
135};
136
137pub mod prelude {
138 //! Default Bounce exports.
139
140 pub use crate::future_notion;
141 pub use crate::BounceStates;
142 pub use crate::Observed;
143 pub use crate::{use_artifacts, Artifact, ArtifactProps};
144 pub use crate::{use_atom, use_atom_setter, use_atom_value, Atom, CloneAtom, UseAtomHandle};
145 pub use crate::{use_future_notion_runner, Deferred, FutureNotion};
146 pub use crate::{use_input_selector_value, InputSelector};
147 pub use crate::{use_notion_applier, WithNotion};
148 pub use crate::{use_selector_value, Selector};
149 pub use crate::{
150 use_slice, use_slice_dispatch, use_slice_value, CloneSlice, Slice, UseSliceHandle,
151 };
152}
153
154// vendored dependencies used by macros.
155#[doc(hidden)]
156pub mod __vendored {
157 pub use futures;
158 pub use once_cell;
159 pub use yew;
160}