Skip to content

Commit

Permalink
chore: Minor code and examples clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jun 22, 2024
1 parent 0f2a401 commit 0f630c3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
4 changes: 2 additions & 2 deletions examples/complex_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn fetch_user(keys: Vec<QueryKey>) -> QueryResult<QueryValue, ()> {
fn User(id: usize) -> Element {
let value = use_get_query([QueryKey::User(id), QueryKey::Users], fetch_user);

println!("Showing user {id}");
println!("Rendering user {id}");

rsx!( p { "{value.result().value():?}" } )
}
Expand All @@ -58,7 +58,7 @@ fn AnotherUser(id: usize) -> Element {
Query::new(fetch_user).initial(initial)
});

println!("Showing another user {id}");
println!("Rendering another user {id}");

rsx!( p { "{value.result().value():?}" } )
}
Expand Down
8 changes: 4 additions & 4 deletions examples/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn User(id: usize) -> Element {
mutate.mutate((0, "Not Marc".to_string()));
};

println!("Showing user {id}");
println!("Rendering user {id}");

rsx!(
p { "{*mutate.result():?}" }
Expand All @@ -54,8 +54,8 @@ fn User(id: usize) -> Element {
fn app() -> Element {
rsx!(
User { id: 0 }
User { id: 0 }
User { id: 0 }
User { id: 0 }
User { id: 1 }
User { id: 2 }
User { id: 3 }
)
}
2 changes: 1 addition & 1 deletion examples/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn User(id: usize) -> Element {
let user_name = use_get_query([QueryKey::User(id)], fetch_user);
let user_age = use_get_query([QueryKey::User(id)], fetch_user_age);

println!("Showing user {id}");
println!("Rendering user {id}");

rsx!(
p { "{user_name.result().value():?}" }
Expand Down
5 changes: 0 additions & 5 deletions src/cached_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ impl<T, E> CachedResult<T, E> {
}
}

/// Check if this result has been mutated at some point
pub(crate) fn has_been_mutated(&self) -> bool {
self.instant.is_some()
}

/// Check if this result has queried it's actual value yet
pub(crate) fn has_been_queried(&self) -> bool {
self.has_been_queried
Expand Down
7 changes: 1 addition & 6 deletions src/use_query_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,11 @@ where

let is_fresh = value.read().unwrap().is_fresh();
let is_loading = value.read().unwrap().is_loading();
let has_been_mutated = value.read().unwrap().has_been_mutated();
let has_been_queried = value.read().unwrap().has_been_queried();

if (!is_fresh && !is_loading) || !has_been_queried {
// Only change to `Loading` if it has been changed at some point
if has_been_mutated {
if has_been_queried {
value.write().unwrap().set_to_loading();
for listener in listeners {
(self.scheduler.peek())(listener);
Expand All @@ -132,10 +131,6 @@ where
// Get the listeners again in case they changed
let QueryListeners { listeners, .. } = self.get_entry(entry);

for listener in listeners {
(self.scheduler.peek())(listener);
}
} else {
for listener in listeners {
(self.scheduler.peek())(listener);
}
Expand Down

0 comments on commit 0f630c3

Please sign in to comment.