(feat): redesign WASM module, add TypeScript SDK, migrate to pnpm
Some checks failed
CI / rustfmt (push) Successful in 17s
CI / wasm build (push) Successful in 1m16s
CI / clippy (push) Successful in 1m28s
CI / test (push) Successful in 1m48s
CI / example (push) Successful in 1m31s
CI / duplicate code (push) Failing after 33s
CI / web client (push) Failing after 34s
CI / cargo-machete (push) Successful in 1m18s
CI / cargo-deny (push) Failing after 3m2s
Some checks failed
CI / rustfmt (push) Successful in 17s
CI / wasm build (push) Successful in 1m16s
CI / clippy (push) Successful in 1m28s
CI / test (push) Successful in 1m48s
CI / example (push) Successful in 1m31s
CI / duplicate code (push) Failing after 33s
CI / web client (push) Failing after 34s
CI / cargo-machete (push) Successful in 1m18s
CI / cargo-deny (push) Failing after 3m2s
This commit is contained in:
parent
89a20044a5
commit
5caa1c9d5f
49 changed files with 3717 additions and 1501 deletions
44
wasm/src/subscription.rs
Normal file
44
wasm/src/subscription.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Minimal message router used by higher-level SDK subscription code.
|
||||
#[wasm_bindgen]
|
||||
pub struct WasmSubscriptionRouter {
|
||||
handlers: HashMap<String, js_sys::Function>,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl WasmSubscriptionRouter {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
handlers: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn subscribe(&mut self, message_type: String, callback: js_sys::Function) {
|
||||
self.handlers.insert(message_type, callback);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn unsubscribe(&mut self, message_type: &str) -> bool {
|
||||
self.handlers.remove(message_type).is_some()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn dispatch(&self, message_type: &str, message: JsValue) -> bool {
|
||||
let Some(callback) = self.handlers.get(message_type) else {
|
||||
return false;
|
||||
};
|
||||
let _ = callback.call1(&JsValue::NULL, &message);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for WasmSubscriptionRouter {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue