2023-04-21 02:23:13 +00:00
|
|
|
use wasm_bindgen::prelude::*;
|
2023-05-11 13:39:31 +00:00
|
|
|
// use serde::{Serialize, Deserialize};
|
|
|
|
use kifu_core::{CoreRequest, CoreResponse};
|
2023-04-21 02:23:13 +00:00
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
extern "C" {
|
|
|
|
#[wasm_bindgen(js_namespace = console)]
|
|
|
|
pub fn log(s: &str);
|
|
|
|
}
|
|
|
|
|
2023-04-21 13:25:21 +00:00
|
|
|
/*
|
2023-04-21 02:23:13 +00:00
|
|
|
#[wasm_bindgen]
|
2023-05-11 13:39:31 +00:00
|
|
|
#[derive(Serialize, Deserialize)]
|
2023-04-21 13:25:21 +00:00
|
|
|
pub struct CoreRequest(kifu_core::Request);
|
2023-05-11 13:39:31 +00:00
|
|
|
*/
|
2023-04-21 02:23:13 +00:00
|
|
|
|
2023-05-11 13:39:31 +00:00
|
|
|
/*
|
2023-04-21 02:23:13 +00:00
|
|
|
#[wasm_bindgen]
|
2023-04-21 13:25:21 +00:00
|
|
|
impl CoreRequest {
|
|
|
|
#[wasm_bindgen(constructor)]
|
|
|
|
pub fn new(request: kifu_core::Request) -> Self {
|
|
|
|
Self(request)
|
|
|
|
}
|
|
|
|
}
|
2023-04-21 02:23:13 +00:00
|
|
|
*/
|
|
|
|
|
2023-04-21 13:25:21 +00:00
|
|
|
/* Somehow uncommenting this code actually causes the module to not load. Maybe a name conflict?
|
|
|
|
* Don't know.
|
|
|
|
*/
|
2023-05-11 13:39:31 +00:00
|
|
|
/*
|
2023-04-21 02:23:13 +00:00
|
|
|
#[wasm_bindgen]
|
2023-05-11 13:39:31 +00:00
|
|
|
#[derive(Serialize, Deserialize)]
|
2023-04-21 13:25:21 +00:00
|
|
|
pub struct CoreResponse(kifu_core::Response);
|
2023-05-11 13:39:31 +00:00
|
|
|
*/
|
2023-04-21 02:23:13 +00:00
|
|
|
|
|
|
|
#[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);
|
2023-04-21 02:23:13 +00:00
|
|
|
|
|
|
|
#[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
|
|
|
}
|
2023-04-21 02:23:13 +00:00
|
|
|
}
|