You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Useful for fetching on component mount, or in response to an Event.
fetch_once fetches once straight away and deserializes to the given type (useful for fetching on mount). It automatically refreshes the view when the response is received.
fetch_later prepares a fetch and but only fetches on do_fetch() being called, useful if a fetch is needed in response to a button click.
Both have optional Msg on response.
Let me know if you have any comment on the API surface. The type parameters are a little busy but this should be able to be reduced in the future.
Simple example:
// fetches a user on mount#[topo::nested]fnfetch_on_mount_example() -> Node<Msg>{let fetch_user = fetch_once::<User,Model,_,_>("user.json",Msg::default());div![fetch_user.fetched_value()]}
Fuller API login example as below:
// fetches a user on log-in click#[topo::nested]fnshow_user_later() -> Node<Msg>{let fetch_user = fetch_later::<User,_>("user.json");ifletSome(user) = fetch_user.fetched_value(){div!["Logged in User: ",
user.name,
div![a![
attrs![At::Href=>"#logout"],"Log out",
mouse_ev(Ev::Click, move |_| {
fetch_user.delete();Msg::default()})]]]}else{div![a![
attrs![At::Href=>"#login"],"Log in",
mouse_ev(Ev::Click, move |_| {
fetch_user.do_fetch::<Model,Msg,Node<Msg>>(Msg::default());Msg::default()})]]}}
and on mount:
#[topo::nested]// fetches a user on mountfnshow_user() -> Node<Msg>{let fetch_user = fetch_once::<User,Model,_,_>("user.json",Msg::default());ifletSome(user) = fetch_user.fetched_value(){div!["Logged in User: ",
user.name,
div![a![
attrs![At::Href=>"#logout"],"Log out",
mouse_ev(Ev::Click, move |_| {
fetch_user.delete();Msg::default()})]]]}else{div![a![attrs![At::Href=>"#login"],"Log in"]]}}
The text was updated successfully, but these errors were encountered:
I'm a simple user. I don't want to learn and remember fetch_once, fetch_later, .fetched_value, .delete(), do_fetch(, etc. Can I just reuse basic API and write something like:
Initial draft of fetch support.
Useful for fetching on component mount, or in response to an Event.
fetch_once
fetches once straight away and deserializes to the given type (useful for fetching on mount). It automatically refreshes the view when the response is received.fetch_later
prepares a fetch and but only fetches ondo_fetch()
being called, useful if a fetch is needed in response to a button click.Both have optional
Msg
on response.Let me know if you have any comment on the API surface. The type parameters are a little busy but this should be able to be reduced in the future.
Simple example:
Fuller API login example as below:
and on mount:
The text was updated successfully, but these errors were encountered: