Switch to using JSON for wasm.
serde_wasm_bindgen was silently dropping many attributes (I suspect it is triggered by serde flatten) so this switches to serializing to JSON for passing values from wasm to js.
This commit is contained in:
parent
64bb597908
commit
8406d37991
@ -52,6 +52,7 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = { version = "0.3.28", optional = true }
|
futures = { version = "0.3.28", optional = true }
|
||||||
|
gloo-utils = "0.2.0"
|
||||||
nom = "7.1.1"
|
nom = "7.1.1"
|
||||||
opentelemetry = { version = "0.20.0", optional = true, default-features = false, features = ["trace", "rt-tokio"] }
|
opentelemetry = { version = "0.20.0", optional = true, default-features = false, features = ["trace", "rt-tokio"] }
|
||||||
opentelemetry-otlp = { version = "0.13.0", optional = true }
|
opentelemetry-otlp = { version = "0.13.0", optional = true }
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
use gloo_utils::format::JsValueSerdeExt;
|
||||||
|
use wasm_bindgen::JsValue;
|
||||||
|
|
||||||
use crate::parser::parse_with_settings;
|
use crate::parser::parse_with_settings;
|
||||||
use crate::settings::GlobalSettings;
|
use crate::settings::GlobalSettings;
|
||||||
use crate::wasm::ParseResult;
|
use crate::wasm::ParseResult;
|
||||||
@ -8,17 +11,15 @@ pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
|||||||
let rust_parsed = match parse_with_settings(org_contents, &GlobalSettings::default()) {
|
let rust_parsed = match parse_with_settings(org_contents, &GlobalSettings::default()) {
|
||||||
Ok(document) => document,
|
Ok(document) => document,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return serde_wasm_bindgen::to_value(&ParseResult::Error(format!("{:?}", err)))
|
return JsValue::from_serde(&ParseResult::Error(format!("{:?}", err))).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let to_wasm_context = ToWasmContext::new(org_contents);
|
let to_wasm_context = ToWasmContext::new(org_contents);
|
||||||
let wasm_document = match rust_parsed.to_wasm(to_wasm_context) {
|
let wasm_document = match rust_parsed.to_wasm(to_wasm_context) {
|
||||||
Ok(document) => document,
|
Ok(document) => document,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return serde_wasm_bindgen::to_value(&ParseResult::Error(format!("{:?}", err)))
|
return JsValue::from_serde(&ParseResult::Error(format!("{:?}", err))).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
serde_wasm_bindgen::to_value(&ParseResult::Success(wasm_document)).unwrap()
|
JsValue::from_serde(&ParseResult::Success(wasm_document)).unwrap()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user