Merge branch 'upstream' into desktop-hot-reload

This commit is contained in:
Evan Almloff committed 2023-01-12 10:59:01 -06:00
commit dc8fcf254b
55 files changed
+1013 -601

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ edition = "2021"
repository = "https://github.com/DioxusLabs/dioxus/"
homepage = "https://dioxuslabs.com"
documentation = "https://dioxuslabs.com"
keywords = ["dom", "ui", "gui", "react", "wasm"]
keywords = ["dom", "ui", "gui", "react", "liveview"]
description = "Build server-side apps with Dioxus"
license = "MIT/Apache-2.0"
+5 -5
View File
@@ -20,13 +20,13 @@
[Website](https://dioxuslabs.com) |
[Guides](https://dioxuslabs.com/guide/) |
[API Docs](https://docs.rs/dioxus-liveview/latest/dioxus-liveview) |
[API Docs](https://docs.rs/dioxus-liveview/latest/dioxus_liveview) |
[Chat](https://discord.gg/XgGxMSkvUM)
## Overview
`dioxus-liveview` provides adapters for running the Dioxus VirtualDom over a websocket connection.
`dioxus-liveview` provides adapters for running the Dioxus VirtualDom over a WebSocket connection.
The current backend frameworks supported include:
@@ -34,9 +34,9 @@ The current backend frameworks supported include:
- Warp
- Salvo
Dioxus-LiveView exports a number of primitives to wire up an app into an existing backend framework.
Dioxus-LiveView exports some primitives to wire up an app into an existing backend framework.
- A threadpool for spawning the `!Send` VirtualDom and interacting with it from the websocket
- A ThreadPool for spawning the `!Send` VirtualDom and interacting with it from WebSockets
- An adapter for transforming various socket types into the `LiveViewSocket` type
- The glue to load the interpreter into your app
@@ -51,5 +51,5 @@ This project is licensed under the [MIT license].
[mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
for inclusion in Dioxus by you shall be licensed as MIT without any additional
terms or conditions.
+11 -2
View File
@@ -12,7 +12,13 @@ class IPC {
let ws = new WebSocket(WS_ADDR);
function ping() {
ws.send("__ping__");
}
ws.onopen = () => {
// we ping every 30 seconds to keep the websocket alive
setInterval(ping, 30000);
ws.send(serializeIpcMessage("initialize"));
};
@@ -21,8 +27,11 @@ class IPC {
};
ws.onmessage = (event) => {
let edits = JSON.parse(event.data);
window.interpreter.handleEdits(edits);
// Ignore pongs
if (event.data != "__pong__") {
let edits = JSON.parse(event.data);
window.interpreter.handleEdits(edits);
}
};
this.ws = ws;
+6 -2
View File
@@ -141,9 +141,13 @@ where
_ = vdom.wait_for_work() => {}
evt = ws.next() => {
match evt {
match evt.as_ref().map(|o| o.as_deref()) {
// respond with a pong every ping to keep the websocket alive
Some(Ok("__ping__")) => {
ws.send("__pong__".to_string()).await?;
}
Some(Ok(evt)) => {
if let Ok(IpcMessage { params }) = serde_json::from_str::<IpcMessage>(&evt) {
if let Ok(IpcMessage { params }) = serde_json::from_str::<IpcMessage>(evt) {
vdom.handle_event(&params.name, params.data.into_any(), params.element, params.bubbles);
}
}