mirror of
https://github.com/enso-org/enso.git
synced 2024-12-25 03:43:41 +03:00
Fix directing JSON data to JS visualizations. (#3984)
This commit is contained in:
parent
b9bf958f2c
commit
a2d8c1d0ab
@ -214,7 +214,7 @@ impl InstanceModel {
|
||||
_ => return Err(DataError::BinaryNotSupported),
|
||||
};
|
||||
let data_json: &serde_json::Value = data_json.deref();
|
||||
let data_js = match serde_wasm_bindgen::to_value(data_json) {
|
||||
let data_js = match json_to_value(data_json) {
|
||||
Ok(value) => value,
|
||||
Err(_) => return Err(DataError::InvalidDataType),
|
||||
};
|
||||
@ -353,3 +353,17 @@ fn get_method(
|
||||
) -> Result<web::Function> {
|
||||
Ok(default())
|
||||
}
|
||||
|
||||
/// Convert the given JSON value to a `JsValue`.
|
||||
///
|
||||
/// Note that we need to use special serializer, as `serde_wasm_bindgen` defaults to outputting
|
||||
/// some special `Map` type that is not supported by the visualization API (rather than proper
|
||||
/// objects).
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn json_to_value(
|
||||
json: &serde_json::Value,
|
||||
) -> std::result::Result<JsValue, serde_wasm_bindgen::Error> {
|
||||
use serde::Serialize;
|
||||
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
||||
json.serialize(&serializer)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user