Skip to content

Commit

Permalink
Print a console.error if koboldCallback is missing (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejhirsz committed Apr 28, 2023
1 parent d4dde20 commit 1bd25ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/kobold/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ export function replaceClass(n,o,v) { n.classList.replace(o,v); }
export function toggleClass(n,c,v) { n.classList.toggle(c,v); }

export function makeEventHandler(c,f) { return (e) => koboldCallback(e,c,f); }
export function checkEventHandler() { if (typeof koboldCallback !== "function") console.error(
`Missing \`koboldCallback\` in global scope.
Add the following to your Trunk.toml:
[build]
pattern_script = "<script type=\\"module\\">import init, { koboldCallback } from '{base}{js}';init('{base}{wasm}');window.koboldCallback = koboldCallback;</script>"
`) }
3 changes: 3 additions & 0 deletions crates/kobold/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ extern "C" {

#[wasm_bindgen(js_name = "makeEventHandler")]
pub(crate) fn make_event_handler(closure: *mut (), vcall: usize) -> JsValue;

#[wasm_bindgen(js_name = "checkEventHandler")]
pub(crate) fn check_event_handler();
}

#[cfg(test)]
Expand Down
3 changes: 3 additions & 0 deletions crates/kobold/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,9 @@ where
pub fn start(view: impl View) {
init_panic_hook();

#[cfg(debug_assertions)]
internal::check_event_handler();

use std::mem::MaybeUninit;
use std::pin::pin;

Expand Down

0 comments on commit 1bd25ca

Please sign in to comment.