Merge pull request #217 from DioxusLabs/jk/serde-wasm-bindgen

feat: use serde-wasm-bindgen crate for speedup
This commit is contained in:
Jonathan Kelley 2022-02-07 19:29:04 -05:00 committed by GitHub
commit 3f5b8b285d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 10 deletions

View file

@ -31,7 +31,7 @@ extern "C" {
pub fn Remove(this: &Interpreter, root: u64);
#[wasm_bindgen(method)]
pub fn CreateTextNode(this: &Interpreter, text: &str, root: u64);
pub fn CreateTextNode(this: &Interpreter, text: JsValue, root: u64);
#[wasm_bindgen(method)]
pub fn CreateElement(this: &Interpreter, tag: &str, root: u64);
@ -49,10 +49,16 @@ extern "C" {
pub fn RemoveEventListener(this: &Interpreter, root: u64, name: &str);
#[wasm_bindgen(method)]
pub fn SetText(this: &Interpreter, root: u64, text: &str);
pub fn SetText(this: &Interpreter, root: u64, text: JsValue);
#[wasm_bindgen(method)]
pub fn SetAttribute(this: &Interpreter, root: u64, field: &str, value: &str, ns: Option<&str>);
pub fn SetAttribute(
this: &Interpreter,
root: u64,
field: &str,
value: JsValue,
ns: Option<&str>,
);
#[wasm_bindgen(method)]
pub fn RemoveAttribute(this: &Interpreter, root: u64, field: &str);

View file

@ -29,6 +29,7 @@ gloo-timers = { version = "0.2.3", features = ["futures"] }
futures-util = "0.3.19"
smallstr = "0.2.0"
dioxus-interpreter-js = { path = "../interpreter", version = "^0.0.0", features = ["web"] }
serde-wasm-bindgen = "0.4.2"
[dependencies.web-sys]
version = "0.3.56"

View file

@ -105,9 +105,7 @@ impl WebsysDom {
DomEdit::InsertAfter { root, n } => self.interpreter.InsertAfter(root, n),
DomEdit::InsertBefore { root, n } => self.interpreter.InsertBefore(root, n),
DomEdit::Remove { root } => self.interpreter.Remove(root),
DomEdit::CreateTextNode { text, root } => {
self.interpreter.CreateTextNode(text, root)
}
DomEdit::CreateElement { tag, root } => self.interpreter.CreateElement(tag, root),
DomEdit::CreateElementNs { tag, root, ns } => {
self.interpreter.CreateElementNs(tag, root, ns)
@ -123,15 +121,27 @@ impl WebsysDom {
DomEdit::RemoveEventListener { root, event } => {
self.interpreter.RemoveEventListener(root, event)
}
DomEdit::SetText { root, text } => self.interpreter.SetText(root, text),
DomEdit::RemoveAttribute { root, name } => {
self.interpreter.RemoveAttribute(root, name)
}
DomEdit::CreateTextNode { text, root } => {
let text = serde_wasm_bindgen::to_value(text).unwrap();
self.interpreter.CreateTextNode(text, root)
}
DomEdit::SetText { root, text } => {
let text = serde_wasm_bindgen::to_value(text).unwrap();
self.interpreter.SetText(root, text)
}
DomEdit::SetAttribute {
root,
field,
value,
ns,
} => self.interpreter.SetAttribute(root, field, value, ns),
DomEdit::RemoveAttribute { root, name } => {
self.interpreter.RemoveAttribute(root, name)
} => {
let value = serde_wasm_bindgen::to_value(value).unwrap();
self.interpreter.SetAttribute(root, field, value, ns)
}
}
}