pub fn dispatch_with<Detail>(
event: &str,
to: Option<&str>,
detail: &Detail,
) -> Result<(), Error>Expand description
Like dispatch, but attaches a serializable detail payload.
detail is serialized with serde_json and becomes event.detail on
the CustomEvent seen by listeners.
§Errors
Returns Error::Serialize if detail cannot be JSON-encoded. Also
returns the same browser-bridge errors as dispatch.
§Examples
Ad-hoc JSON:
use wasm_liveview as lv;
lv::dispatch_with(
"wasm:score",
Some("#score"),
&serde_json::json!({ "delta": 5 }),
)?;Typed payload via derive(Serialize):
use wasm_liveview as lv;
#[derive(serde::Serialize)]
struct ScoreDelta { delta: i32 }
lv::dispatch_with("wasm:score", Some("#score"), &ScoreDelta { delta: 5 })?;