-
Notifications
You must be signed in to change notification settings - Fork 46
Added explanation of the fetch module. #57
base: master
Are you sure you want to change the base?
Added explanation of the fetch module. #57
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this!
src/concepts/services/fetch.md
Outdated
if meta.status.is_success() { | ||
match data.message { | ||
"success" => { | ||
Self::Message::ReceiveLocation(data.clone()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this clone needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, I think not.
src/concepts/services/fetch.md
Outdated
if meta.status.is_success() { | ||
match data.message { | ||
"success" => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be more succinct here: if meta.status.is_success() && data.message == "success"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (I think)!
src/concepts/services/fetch.md
Outdated
fn view(&self) -> Html { | ||
html! { | ||
<> | ||
{if self.fetching { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please break out this block and the match self.iss
block into their own methods on FetchServiceExample
? I'd like the examples to set a good precedent for splitting up view logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (I think)!
Co-authored-by: Justin Starry <[email protected]>
Co-authored-by: Justin Starry <[email protected]>
Co-authored-by: Justin Starry <[email protected]>
Co-authored-by: Justin Starry <[email protected]>
Co-authored-by: Justin Starry <[email protected]>
// split up the response into the HTTP data about the request result and data from the request | ||
let (meta, Json(data)) = response.into_parts(); | ||
if meta.status.is_success() && data.message == "success" { | ||
Self::Message::ReceiveLocation(match data { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What type is data
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this (I think).
src/concepts/services/fetch.md
Outdated
ReceiveLocation(location) => { | ||
self.iss = location; | ||
self.fetching = false; | ||
// we want to redraw so that the page no longer says 'fetching...' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: and also display the location!
link: ComponentLink<Self> | ||
} | ||
|
||
impl FetchServiceExample { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can you move this impl block under the impl Component
block? It flows better because from top to bottom you see the methods right after seeing
fn view(&self) -> Html {
html! {
<>
{self.is_fetching()}
{self.view_iss_location()}
</>
}
}
// handle errors more properly than this | ||
Err(_) => panic!("Could not handle this error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should handle the error to show a more complete example? Not sure if people get tripped up on error handling or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add some error handling.
No description provided.