monorepo/kifu/ffi/wasm/src/lib.rs

27 lines
649 B
Rust
Raw Normal View History

2023-05-11 13:39:31 +00:00
use kifu_core::{CoreRequest, CoreResponse};
2023-05-13 16:29:57 +00:00
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
pub fn log(s: &str);
}
#[wasm_bindgen]
2023-04-21 13:25:21 +00:00
#[derive(Debug)]
2023-05-11 13:39:31 +00:00
pub struct CoreApp(kifu_core::CoreApp);
#[wasm_bindgen]
2023-04-21 13:25:21 +00:00
impl CoreApp {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
2023-05-11 13:39:31 +00:00
Self(kifu_core::CoreApp::new())
2023-04-21 13:25:21 +00:00
}
#[wasm_bindgen]
2023-05-11 13:39:31 +00:00
pub async fn dispatch(&self, param: &JsValue) -> JsValue {
let request: CoreRequest = serde_wasm_bindgen::from_value(param.clone()).unwrap();
serde_wasm_bindgen::to_value(&self.0.dispatch(request).await).unwrap()
2023-04-21 13:25:21 +00:00
}
}