Return Option<Value> from fun on replace_with to all user to return None (remove the value and not replace with Null)

This commit is contained in:
Guy Korland
2019-08-26 15:41:43 +03:00
committed by freestrings
parent e0db04aed9
commit 17a8608392
6 changed files with 24 additions and 16 deletions

View File

@ -56,24 +56,24 @@ where
}
}
fn replace_fun(v: Value, fun: &js_sys::Function) -> Value {
fn replace_fun(v: Value, fun: &js_sys::Function) -> Option<Value> {
match JsValue::from_serde(&v) {
Ok(js_v) => match fun.call1(&JsValue::NULL, &js_v) {
Ok(result) => match into_serde_json(&result) {
Ok(json) => json,
Ok(json) => Some(json),
Err(e) => {
console_error!("replace_with - closure returned a invalid JSON: {:?}", e);
Value::Null
Some(Value::Null)
}
},
Err(e) => {
console_error!("replace_with - fail to call closure: {:?}", e);
Value::Null
Some(Value::Null)
}
},
Err(e) => {
console_error!("replace_with - invalid JSON object: {:?}", e);
Value::Null
Some(Value::Null)
}
}
}