tracing-wasm and init function

This commit is contained in:
Simon Gardling
2022-02-23 09:56:44 -05:00
parent 42015c27a7
commit 6ab99329b2
3 changed files with 18 additions and 4 deletions

View File

@@ -21,6 +21,23 @@ extern "C" {
fn log(s: &str);
}
#[wasm_bindgen(start)]
pub fn init() {
log("Initializing...");
// See performance in browser profiler!
log("Initializing tracing_wasm...");
tracing_wasm::set_as_global_default();
log("Initialized tracing_wasm!");
// Used in order to hook into `panic!()` to log in the browser's console
log("Initializing console_error_panic_hook...");
panic::set_hook(Box::new(console_error_panic_hook::hook));
log("Initialized console_error_panic_hook!");
log("Finished initializing!");
}
// Manages Chart generation and caching of values
#[wasm_bindgen]
pub struct ChartManager {
@@ -54,9 +71,6 @@ impl ChartManager {
}
}
// Used in order to hook into `panic!()` to log in the browser's console
pub fn init_panic_hook() { panic::set_hook(Box::new(console_error_panic_hook::hook)); }
// Tests function to make sure it's able to be parsed. Returns the string of the Error produced, or an empty string if it runs successfully.
pub fn test_func(function_string: String) -> String {
// Factorials do not work, and it would be really difficult to make them work