mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
debug and error logging
This commit is contained in:
parent
edf85edfc5
commit
d6722adb4d
@ -19,6 +19,12 @@ extern "C" {
|
|||||||
// `log(..)`
|
// `log(..)`
|
||||||
#[wasm_bindgen(js_namespace = console)]
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
pub fn log(s: &str);
|
pub fn log(s: &str);
|
||||||
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
|
pub fn debug(s: &str);
|
||||||
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
|
pub fn warn(s: &str);
|
||||||
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
|
pub fn error(s: &str);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
@ -30,3 +36,33 @@ macro_rules! console_log {
|
|||||||
(log(&format_args!($($t)*).to_string()))
|
(log(&format_args!($($t)*).to_string()))
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! console_debug {
|
||||||
|
// Note that this is using the `log` function imported above during
|
||||||
|
// `bare_bones`
|
||||||
|
($($t:tt)*) => {{
|
||||||
|
use crate::typings::debug;
|
||||||
|
(debug(&format_args!($($t)*).to_string()))
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! console_error {
|
||||||
|
// Note that this is using the `log` function imported above during
|
||||||
|
// `bare_bones`
|
||||||
|
($($t:tt)*) => {{
|
||||||
|
use crate::typings::error;
|
||||||
|
(error(&format_args!($($t)*).to_string()))
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! console_warn {
|
||||||
|
// Note that this is using the `log` function imported above during
|
||||||
|
// `bare_bones`
|
||||||
|
($($t:tt)*) => {{
|
||||||
|
use crate::typings::warn;
|
||||||
|
(warn(&format_args!($($t)*).to_string()))
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use crate::console_log;
|
use crate::{console_debug, console_error, console_log};
|
||||||
use reqwasm::http;
|
use reqwasm::http;
|
||||||
use sycamore::context::{use_context, ContextProvider, ContextProviderProps};
|
use sycamore::context::{use_context, ContextProvider, ContextProviderProps};
|
||||||
use sycamore::futures::spawn_local_in_scope;
|
use sycamore::futures::spawn_local_in_scope;
|
||||||
@ -39,7 +39,7 @@ impl AppService {
|
|||||||
if resp.status() != 200 {
|
if resp.status() != 200 {
|
||||||
return Err(format!("Status: {}", resp.status()));
|
return Err(format!("Status: {}", resp.status()));
|
||||||
} else {
|
} else {
|
||||||
console_log!("We got a valid response back!");
|
console_debug!("We got a valid response back!");
|
||||||
let recipe_list = match resp.json::<Vec<String>>().await {
|
let recipe_list = match resp.json::<Vec<String>>().await {
|
||||||
Ok(recipes) => recipes,
|
Ok(recipes) => recipes,
|
||||||
Err(e) => return Err(format!("Eror getting recipe list as json {}", e)),
|
Err(e) => return Err(format!("Eror getting recipe list as json {}", e)),
|
||||||
@ -49,16 +49,13 @@ impl AppService {
|
|||||||
let recipe = match parse::as_recipe(&r) {
|
let recipe = match parse::as_recipe(&r) {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
console_log!("Error parsing recipe {}", e);
|
console_error!("Error parsing recipe {}", e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console_log!("We parsed a recipe {}", recipe.title);
|
console_debug!("We parsed a recipe {}", recipe.title);
|
||||||
parsed_list.push(recipe);
|
parsed_list.push(recipe);
|
||||||
}
|
}
|
||||||
// TODO(jwall): It would appear that their API doesn't support this
|
|
||||||
// model for async operations.
|
|
||||||
//self.recipes = parsed_list;
|
|
||||||
return Ok(parsed_list);
|
return Ok(parsed_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +89,7 @@ fn recipe_list() -> View<G> {
|
|||||||
#[component(UI<G>)]
|
#[component(UI<G>)]
|
||||||
pub fn ui() -> View<G> {
|
pub fn ui() -> View<G> {
|
||||||
let app_state = AppService::new();
|
let app_state = AppService::new();
|
||||||
|
console_log!("Starting UI");
|
||||||
spawn_local_in_scope({
|
spawn_local_in_scope({
|
||||||
let mut app_state = app_state.clone();
|
let mut app_state = app_state.clone();
|
||||||
async move {
|
async move {
|
||||||
@ -100,7 +97,7 @@ pub fn ui() -> View<G> {
|
|||||||
Ok(recipes) => {
|
Ok(recipes) => {
|
||||||
app_state.set_recipes(recipes);
|
app_state.set_recipes(recipes);
|
||||||
}
|
}
|
||||||
Err(msg) => console_log!("Failed to get recipes {}", msg),
|
Err(msg) => console_error!("Failed to get recipes {}", msg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user