allow disabling logging
This commit is contained in:
1 parent
82048737f4
commit
9be1df1451
2 files changed
+31
-17
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
1. Hot reloading allows much faster iteration times inside of rsx calls by interpreting them and streaming the edits.
|
1. Hot reloading allows much faster iteration times inside of rsx calls by interpreting them and streaming the edits.
|
||||||
2. It is useful when changing the styling/layout of a program, but will not help with changing the logic of a program.
|
2. It is useful when changing the styling/layout of a program, but will not help with changing the logic of a program.
|
||||||
3. Currently the cli only implements hot reloading for the web renderer. For TUI, desktop, and liveview you can use the hot reload macro.
|
3. Currently the cli only implements hot reloading for the web renderer. For TUI, desktop, and LiveView you can use the hot reload macro instead.
|
||||||
|
|
||||||
# Web
|
# Web
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ dioxus serve --hot-reload
|
|||||||
|
|
||||||
# Desktop/Liveview/TUI
|
# Desktop/Liveview/TUI
|
||||||
|
|
||||||
For desktop, LiveView, and tui, you can place the hot reload macro before your app runs to enable hot reloading.
|
For desktop, LiveView, and tui, you can place the hot reload macro at the top of your main function to enable hot reloading.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ Add the following to your main function:
|
|||||||
|
|
||||||
```rust
|
```rust
|
||||||
fn main() {
|
fn main() {
|
||||||
dioxus::hot_reload_init!();
|
hot_reload_init!();
|
||||||
// launch your application
|
// launch your application
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -46,10 +46,6 @@ cargo run
|
|||||||
2. Change some code within a rsx or render macro
|
2. Change some code within a rsx or render macro
|
||||||
3. Save and watch the style change without recompiling
|
3. Save and watch the style change without recompiling
|
||||||
|
|
||||||
## Custom renders
|
|
||||||
|
|
||||||
For custom renderers
|
|
||||||
|
|
||||||
# Limitations
|
# Limitations
|
||||||
1. The interpreter can only use expressions that existed on the last full recompile. If you introduce a new variable or expression to the rsx call, it will trigger a full recompile to capture the expression.
|
1. The interpreter can only use expressions that existed on the last full recompile. If you introduce a new variable or expression to the rsx call, it will trigger a full recompile to capture the expression.
|
||||||
2. Components and Iterators can contain arbitrary rust code and will trigger a full recompile when changed.
|
2. Components and Iterators can contain arbitrary rust code and will trigger a full recompile when changed.
|
||||||
@@ -12,7 +12,7 @@ use interprocess::local_socket::{LocalSocketListener, LocalSocketStream};
|
|||||||
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
|
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
|
||||||
|
|
||||||
/// Initialize the hot reloading listener on the given path
|
/// Initialize the hot reloading listener on the given path
|
||||||
pub fn init(root_path: &'static str, listening_paths: &'static [&'static str]) {
|
pub fn init(root_path: &'static str, listening_paths: &'static [&'static str], log: bool) {
|
||||||
if let Ok(crate_dir) = PathBuf::from_str(root_path) {
|
if let Ok(crate_dir) = PathBuf::from_str(root_path) {
|
||||||
let temp_file = std::env::temp_dir().join("@dioxusin");
|
let temp_file = std::env::temp_dir().join("@dioxusin");
|
||||||
let channels = Arc::new(Mutex::new(Vec::new()));
|
let channels = Arc::new(Mutex::new(Vec::new()));
|
||||||
@@ -41,7 +41,9 @@ pub fn init(root_path: &'static str, listening_paths: &'static [&'static str]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
channels.lock().unwrap().push(connection);
|
channels.lock().unwrap().push(connection);
|
||||||
println!("Connected to hot reloading 🚀");
|
if log {
|
||||||
|
println!("Connected to hot reloading 🚀");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +96,11 @@ pub fn init(root_path: &'static str, listening_paths: &'static [&'static str]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateResult::NeedsRebuild => {
|
UpdateResult::NeedsRebuild => {
|
||||||
println!("Rebuild needed... shutting down hot reloading");
|
if log {
|
||||||
|
println!(
|
||||||
|
"Rebuild needed... shutting down hot reloading"
|
||||||
|
);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,14 +158,26 @@ pub fn connect(mut f: impl FnMut(Template<'static>) + Send + 'static) {
|
|||||||
/// Pass any number of paths to listen for changes on relative to the crate root as strings.
|
/// Pass any number of paths to listen for changes on relative to the crate root as strings.
|
||||||
/// If no paths are passed, it will listen on the src and examples folders.
|
/// If no paths are passed, it will listen on the src and examples folders.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! hot_reload_init_inner {
|
macro_rules! hot_reload_init {
|
||||||
() => {
|
($($t: ident)*) => {
|
||||||
dioxus_hot_reload::init(core::env!("CARGO_MANIFEST_DIR"), &["src", "examples"])
|
#[cfg(debug_assertions)]
|
||||||
|
dioxus_hot_reload::init(core::env!("CARGO_MANIFEST_DIR"), &["src", "examples"], hot_reload_init!(log: $($t)*))
|
||||||
};
|
};
|
||||||
|
|
||||||
($($paths: literal),*) => {
|
($($paths: literal),* $(,)? $($t: ident)*) => {
|
||||||
dioxus_hot_reload::init(core::env!("CARGO_MANIFEST_DIR"), &[$($paths),*])
|
#[cfg(debug_assertions)]
|
||||||
|
dioxus_hot_reload::init(core::env!("CARGO_MANIFEST_DIR"), &[$($paths),*], hot_reload_init!(log: $($t)*))
|
||||||
|
};
|
||||||
|
|
||||||
|
(log:) => {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
(log: enable logging) => {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
(log: disable logging) => {
|
||||||
|
false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use hot_reload_init_inner as hot_reload_init;
|
|
||||||
Reference in new issue
Block a user