From 6ab99329b2cf60a7237e4c331ce4e5478ffbc2ad Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 23 Feb 2022 09:56:44 -0500 Subject: [PATCH] tracing-wasm and init function --- Cargo.toml | 1 + src/lib.rs | 20 +++++++++++++++++--- www/index.js | 1 - 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b2e7896..bb73b8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,4 @@ wee_alloc = "0.4.5" web-sys = { version = "0.3.56", features = ["HtmlCanvasElement"] } meval = { git = "https://github.com/Titaniumtown/meval-rs.git" } console_error_panic_hook = "0.1.7" +tracing-wasm = "0.2.1" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index df6a9ba..bdb24a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 diff --git a/www/index.js b/www/index.js index 1973f30..4edd38e 100644 --- a/www/index.js +++ b/www/index.js @@ -27,7 +27,6 @@ export function main() { /** This function is used in `bootstrap.js` to setup imports. */ export function setup(WasmChart) { ChartManager = WasmChart; - ChartManager.init_panic_hook(); // Allows `panic!()` to log in the browser's console } /** Add event listeners. */