Skip to content

Commit e6c75fb

Browse files
committed
chore: Clean up
1 parent dd0a408 commit e6c75fb

File tree

3 files changed

+19
-37
lines changed

3 files changed

+19
-37
lines changed

examples/queries.rs

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,27 @@ enum QueryValue {
3232
}
3333

3434
async fn fetch_user(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryError> {
35-
if let Some(QueryKey::User(id)) = keys.first() {
36-
println!("Fetching name of user {id}");
37-
sleep(Duration::from_millis(650)).await;
38-
match id {
39-
0 => Ok(QueryValue::UserName("Marc".to_string())),
40-
_ => Err(QueryError::UserNotFound(*id)),
41-
}
42-
} else {
43-
Err(QueryError::Unknown)
35+
let Some(QueryKey::User(id)) = keys.first() else {
36+
return Err(QueryError::Unknown);
37+
};
38+
println!("Fetching name of user {id}");
39+
sleep(Duration::from_millis(650)).await;
40+
match id {
41+
0 => Ok(QueryValue::UserName("Marc".to_string())),
42+
_ => Err(QueryError::UserNotFound(*id)),
4443
}
4544
}
4645

4746
async fn fetch_user_age(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryError> {
48-
if let Some(QueryKey::User(id)) = keys.first() {
49-
println!("Fetching age of user {id}");
50-
sleep(Duration::from_millis(1000)).await;
51-
match id {
52-
0 => Ok(QueryValue::UserAge(0)),
53-
_ => Err(QueryError::UserNotFound(*id)),
54-
}
55-
} else {
56-
Err(QueryError::Unknown)
57-
}
58-
}
59-
60-
#[derive(Debug)]
61-
enum MutationError {}
62-
63-
#[derive(PartialEq, Debug)]
64-
enum MutationValue {
65-
UserUpdated(usize),
66-
}
67-
68-
async fn update_user((id, _name): (usize, String)) -> MutationResult<MutationValue, MutationError> {
69-
println!("Mutating user");
47+
let Some(QueryKey::User(id)) = keys.first() else {
48+
return Err(QueryError::Unknown);
49+
};
50+
println!("Fetching age of user {id}");
7051
sleep(Duration::from_millis(1000)).await;
71-
Ok(MutationValue::UserUpdated(id))
52+
match id {
53+
0 => Ok(QueryValue::UserAge(0)),
54+
_ => Err(QueryError::UserNotFound(*id)),
55+
}
7256
}
7357

7458
#[allow(non_snake_case)]
@@ -86,11 +70,9 @@ fn User(id: usize) -> Element {
8670
}
8771

8872
fn app() -> Element {
89-
let mutate = use_mutation(update_user);
9073
let client = use_init_query_client::<QueryValue, QueryError, QueryKey>();
9174

9275
let refresh = move |_| async move {
93-
mutate.mutate_async((0, "Not Marc".to_string())).await;
9476
client.invalidate_queries(&[QueryKey::User(0)]);
9577
};
9678

src/cached_result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct CachedResult<T, E> {
1212
}
1313

1414
impl<T, E> CachedResult<T, E> {
15-
pub fn new(value: QueryState<T, E>) -> Self {
15+
pub(crate) fn new(value: QueryState<T, E>) -> Self {
1616
Self {
1717
value,
1818
..Default::default()
@@ -25,7 +25,7 @@ impl<T, E> CachedResult<T, E> {
2525
}
2626

2727
/// Set this result's value
28-
pub fn set_value(&mut self, new_value: QueryState<T, E>) {
28+
pub(crate) fn set_value(&mut self, new_value: QueryState<T, E>) {
2929
self.value = new_value;
3030
self.instant = Some(Instant::now());
3131
}

src/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<T, E> QueryState<T, E> {
2525
matches!(self, QueryState::Loading(..))
2626
}
2727

28-
pub fn set_loading(&mut self) {
28+
pub(crate) fn set_loading(&mut self) {
2929
let result = mem::replace(self, Self::Loading(None)).into();
3030
if let Some(v) = result {
3131
*self = Self::Loading(Some(v))

0 commit comments

Comments
 (0)