mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Complete some TODOs (#1304)
* Complete some `TODO`s * Fix error handling. * Simplify things. * Update changelogs.
This commit is contained in:
parent
8d78620f4f
commit
21a8228d55
@ -20,7 +20,7 @@ END TEMPLATE-->
|
||||
- #### 🛠 Fixes
|
||||
- None
|
||||
- #### 🚨 Breaking changes
|
||||
- None
|
||||
- The `unit_state` module has been removed.
|
||||
|
||||
|
||||
## ✨ **0.13.0** *2020-5-12*
|
||||
|
||||
@ -74,14 +74,6 @@ pub mod components;
|
||||
#[cfg(feature = "router")]
|
||||
pub mod router;
|
||||
|
||||
/// TODO remove this
|
||||
/// Contains aliases and functions for working with this library using a state of type `()`.
|
||||
#[cfg(feature = "unit_alias")]
|
||||
pub mod unit_state {
|
||||
define_router_state!(());
|
||||
pub use router_state::*;
|
||||
}
|
||||
|
||||
/// Prelude module that can be imported when working with the yew_router
|
||||
pub mod prelude {
|
||||
pub use super::matcher::Captures;
|
||||
|
||||
@ -13,6 +13,15 @@
|
||||
|
||||
END TEMPLATE-->
|
||||
|
||||
## ✨ **0.3.0** *(DATE)*
|
||||
|
||||
- #### ⚡️ Features
|
||||
- Sample
|
||||
- #### 🛠 Fixes
|
||||
- Sample
|
||||
- #### 🚨 Breaking changes
|
||||
- `FetchAction::Success` has been renamed to `FetchAction::Fetched`
|
||||
|
||||
## ✨ **v0.2.0** *11/18/19*
|
||||
- #### ⚡️ Features
|
||||
- Add new `FetchRequest` trait, `fetch_resource()` function, and `FetchState` enum
|
||||
|
||||
@ -68,7 +68,7 @@ impl<REQ: Default, RES: PartialEq> Fetch<REQ, RES> {
|
||||
match action {
|
||||
FetchAction::NotFetching => self.set_not_fetching(),
|
||||
FetchAction::Fetching => self.set_fetching(),
|
||||
FetchAction::Success(res) => self.set_fetched(res),
|
||||
FetchAction::Fetched(res) => self.set_fetched(res),
|
||||
FetchAction::Failed(err) => self.set_failed(err),
|
||||
}
|
||||
}
|
||||
@ -138,7 +138,7 @@ impl<REQ, RES> Fetch<REQ, RES> {
|
||||
let req_type: PhantomData<T> = PhantomData;
|
||||
async move {
|
||||
let fetch_state = match fetch_resource(request, req_type).await {
|
||||
Ok(response) => FetchAction::Success(response),
|
||||
Ok(response) => FetchAction::Fetched(response),
|
||||
Err(err) => FetchAction::Failed(err),
|
||||
};
|
||||
|
||||
@ -159,8 +159,7 @@ impl<REQ, RES> Fetch<REQ, RES> {
|
||||
/// # Panics
|
||||
/// If the Fetch wrapper doesn't contain an instance of a response, this function will panic.
|
||||
pub fn unwrap(self) -> RES {
|
||||
// TODO, actually provide some diagnostic here.
|
||||
self.res().unwrap()
|
||||
self.res().expect("No response body is present.")
|
||||
}
|
||||
|
||||
/// Gets the response body (if present).
|
||||
@ -230,7 +229,7 @@ impl<REQ: FetchRequest> Fetch<REQ, REQ::ResponseBody> {
|
||||
let req_type: PhantomData<REQ> = PhantomData;
|
||||
async move {
|
||||
let fetch_state = match fetch_resource(request, req_type).await {
|
||||
Ok(response) => FetchAction::Success(response),
|
||||
Ok(response) => FetchAction::Fetched(response),
|
||||
Err(err) => FetchAction::Failed(err),
|
||||
};
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ use crate::NeqAssign;
|
||||
pub enum FetchAction<T> {
|
||||
NotFetching,
|
||||
Fetching,
|
||||
Success(T), // TODO rename to Fetched(T)
|
||||
Fetched(T),
|
||||
Failed(FetchError),
|
||||
}
|
||||
|
||||
@ -20,14 +20,14 @@ impl<T> FetchAction<T> {
|
||||
/// Returns a reference to the Success case
|
||||
pub fn success(&self) -> Option<&T> {
|
||||
match self {
|
||||
FetchAction::Success(value) => Some(value),
|
||||
FetchAction::Fetched(value) => Some(value),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the value out of the fetch state if it is a `Success` variant.
|
||||
pub fn unwrap(self) -> T {
|
||||
if let FetchAction::Success(value) = self {
|
||||
if let FetchAction::Fetched(value) = self {
|
||||
value
|
||||
} else {
|
||||
panic!("Could not unwrap value of FetchState");
|
||||
@ -39,14 +39,14 @@ impl<T> FetchAction<T> {
|
||||
match self {
|
||||
FetchAction::NotFetching => FetchAction::NotFetching,
|
||||
FetchAction::Fetching => FetchAction::NotFetching,
|
||||
FetchAction::Success(t) => FetchAction::Success(f(t)),
|
||||
FetchAction::Fetched(t) => FetchAction::Fetched(f(t)),
|
||||
FetchAction::Failed(e) => FetchAction::Failed(e),
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies a function that mutates the response if the Action is the success case.
|
||||
pub fn alter<F: Fn(&mut T)>(&mut self, f: F) {
|
||||
if let FetchAction::Success(t) = self {
|
||||
if let FetchAction::Fetched(t) = self {
|
||||
f(t)
|
||||
}
|
||||
}
|
||||
@ -56,7 +56,7 @@ impl<T> FetchAction<T> {
|
||||
match self {
|
||||
FetchAction::NotFetching => FetchAction::NotFetching,
|
||||
FetchAction::Fetching => FetchAction::NotFetching,
|
||||
FetchAction::Success(t) => FetchAction::Success(t),
|
||||
FetchAction::Fetched(t) => FetchAction::Fetched(t),
|
||||
FetchAction::Failed(e) => FetchAction::Failed(e.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user