feat: move rpc to handler
This commit is contained in:
1 parent
9e04ce5342
commit
f006f50317
2 files changed
+16
-29
No files matched your search
+1
-1
@@ -16,7 +16,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
p {
|
p {
|
||||||
a {
|
a {
|
||||||
href: "http://dioxuslabs.com/",
|
href: "http://dioxuslabs.com/",
|
||||||
"browser-open": "false",
|
prevent_default: "onclick",
|
||||||
onclick: |_| {
|
onclick: |_| {
|
||||||
println!("Hello Dioxus");
|
println!("Hello Dioxus");
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -343,6 +343,7 @@ class Interpreter {
|
|||||||
this.listeners[event_name] = true;
|
this.listeners[event_name] = true;
|
||||||
|
|
||||||
this.root.addEventListener(event_name, (event) => {
|
this.root.addEventListener(event_name, (event) => {
|
||||||
|
|
||||||
const target = event.target;
|
const target = event.target;
|
||||||
const real_id = target.getAttribute(`dioxus-id`);
|
const real_id = target.getAttribute(`dioxus-id`);
|
||||||
|
|
||||||
@@ -356,6 +357,20 @@ class Interpreter {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(event);
|
||||||
|
if (event.type == "click") {
|
||||||
|
event.preventDefault();
|
||||||
|
if (should_prevent_default !== `onclick`) {
|
||||||
|
console.log(event.target.getAttribute("href"));
|
||||||
|
if(element.tagName == "A") {
|
||||||
|
rpc.call("browser_open", {
|
||||||
|
mounted_dom_id: parseInt(real_id),
|
||||||
|
href: event.target.getAttribute("href")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (real_id == null) {
|
if (real_id == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -401,34 +416,6 @@ class Interpreter {
|
|||||||
break;
|
break;
|
||||||
case "dangerous_inner_html":
|
case "dangerous_inner_html":
|
||||||
node.innerHTML = value;
|
node.innerHTML = value;
|
||||||
break;
|
|
||||||
case "href":
|
|
||||||
|
|
||||||
if (node.tagName == "A") {
|
|
||||||
// open the <a> tag in browser
|
|
||||||
node.setAttribute("browser-href", value);
|
|
||||||
node.setAttribute("href", "#");
|
|
||||||
|
|
||||||
node.addEventListener("click", function(event) {
|
|
||||||
|
|
||||||
const target = event.target;
|
|
||||||
const real_id = target.getAttribute(`dioxus-id`);
|
|
||||||
|
|
||||||
if (target.getAttribute("browser-open") != "false") {
|
|
||||||
rpc.call("browser_open", {
|
|
||||||
mounted_dom_id: parseInt(real_id),
|
|
||||||
href: target.getAttribute("browser-href"),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
window.location = target.getAttribute("browser-href");
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
} else {
|
|
||||||
node.setAttribute(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
|
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
|
||||||
|
|||||||
Reference in new issue
Block a user