Simplify cli-config, hotreload -> devtools (drop to 0 deps, fast compile times) (#2975)
* simplify cli-config crate * clean up configs * add devtools crate, update cargo imports * fix serve addr, fix websocket proxy issue * add comment about opt profiles * rename hot-reload to devtools
This commit is contained in:
1 parent
8203ee571f
commit
3fb1f739d1
58 files changed
+1131
-1654
No files matched your search
@@ -0,0 +1,31 @@
|
||||
[package]
|
||||
name = "dioxus-devtools"
|
||||
authors = ["Jonathan Kelley", "Evan Almloff"]
|
||||
version = { workspace = true }
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/DioxusLabs/dioxus/"
|
||||
homepage = "https://dioxuslabs.com/learn/0.4/migration/hot_reload"
|
||||
description = "Hot reloading utilities for Dioxus"
|
||||
keywords = ["dom", "ui", "gui", "react", "hot-reloading"]
|
||||
|
||||
[dependencies]
|
||||
dioxus-signals = { workspace = true }
|
||||
dioxus-core = { workspace = true, features = ["serialize"] }
|
||||
dioxus-devtools-types = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
# hot reloading serve
|
||||
tracing = { workspace = true }
|
||||
warnings.workspace = true
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
tungstenite = { version = "0.23.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
serde_json = "1.0.91"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
|
||||
@@ -0,0 +1,59 @@
|
||||
use dioxus_core::{ScopeId, VirtualDom};
|
||||
pub use dioxus_devtools_types::*;
|
||||
use dioxus_signals::Writable;
|
||||
use warnings::Warning;
|
||||
|
||||
/// Applies template and literal changes to the VirtualDom
|
||||
///
|
||||
/// Assets need to be handled by the renderer.
|
||||
pub fn apply_changes(dom: &VirtualDom, msg: &HotReloadMsg) {
|
||||
dom.runtime().on_scope(ScopeId::ROOT, || {
|
||||
let ctx = dioxus_signals::get_global_context();
|
||||
|
||||
for template in &msg.templates {
|
||||
let id = &template.location;
|
||||
let value = template.template.clone();
|
||||
if let Some(mut signal) = ctx.get_signal_with_key(id) {
|
||||
dioxus_signals::warnings::signal_read_and_write_in_reactive_scope::allow(|| {
|
||||
dioxus_signals::warnings::signal_write_in_component_body::allow(|| {
|
||||
signal.set(Some(value));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Connect to the devserver and handle its messages with a callback.
|
||||
///
|
||||
/// This doesn't use any form of security or protocol, so it's not safe to expose to the internet.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn connect(endpoint: String, mut callback: impl FnMut(DevserverMsg) + Send + 'static) {
|
||||
std::thread::spawn(move || {
|
||||
let (mut websocket, _req) = match tungstenite::connect(endpoint.clone()) {
|
||||
Ok((websocket, req)) => (websocket, req),
|
||||
Err(err) => {
|
||||
eprintln!(
|
||||
"Failed to connect to devserver at {} because {}",
|
||||
endpoint, err
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
while let Ok(msg) = websocket.read() {
|
||||
match msg {
|
||||
tungstenite::Message::Text(text) => {
|
||||
if let Ok(msg) = serde_json::from_str(&text) {
|
||||
callback(msg);
|
||||
} else {
|
||||
eprintln!("Failed to parse message from devserver: {:?}", text);
|
||||
}
|
||||
}
|
||||
msg => {
|
||||
println!("Received a non-text message: {:?}", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user