change rebuild_handler to rebuild_command
This commit is contained in:
1 parent
22f86ed464
commit
31e21aaa79
2 files changed
+14
-3
No files matched your search
@@ -97,6 +97,15 @@ fn main(){
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To rebuild the application when the logic changes, you can use the `with_rebuild_command` function on the config builder. This command will be called when hot reloading fails to quickly update the rsx:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn main(){
|
||||||
|
hot_reload_init!(Config::new().with_rebuild_command("cargo run"));
|
||||||
|
// launch your application
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
If you are using a namespace other than html, you can implement the [HotReloadingContext](https://docs.rs/dioxus-rsx/latest/dioxus_rsx/trait.HotReloadingContext.html) trait to provide a mapping between the rust names of your elements/attributes and the resulting strings.
|
If you are using a namespace other than html, you can implement the [HotReloadingContext](https://docs.rs/dioxus-rsx/latest/dioxus_rsx/trait.HotReloadingContext.html) trait to provide a mapping between the rust names of your elements/attributes and the resulting strings.
|
||||||
|
|
||||||
You can then provide the Context to the builder to make hot reloading work with your custom namespace:
|
You can then provide the Context to the builder to make hot reloading work with your custom namespace:
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ impl<Ctx: HotReloadingContext> Config<Ctx> {
|
|||||||
/// Set the command to run to rebuild the project
|
/// Set the command to run to rebuild the project
|
||||||
///
|
///
|
||||||
/// For example to restart the application after a change is made, you could use `cargo run`
|
/// For example to restart the application after a change is made, you could use `cargo run`
|
||||||
pub const fn with_rebuild_handler(self, rebuild_with: &'static str) -> Self {
|
pub const fn with_rebuild_command(self, rebuild_with: &'static str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
rebuild_with: Some(rebuild_with),
|
rebuild_with: Some(rebuild_with),
|
||||||
..self
|
..self
|
||||||
@@ -198,7 +198,8 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
|
|||||||
}
|
}
|
||||||
execute::shell(rebuild_command)
|
execute::shell(rebuild_command)
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("Failed to rebuild the application. Is cargo installed?");
|
.expect("Failed to spawn the rebuild command");
|
||||||
|
|
||||||
for channel in &mut *channels.lock().unwrap() {
|
for channel in &mut *channels.lock().unwrap() {
|
||||||
send_msg(HotReloadMsg::Shutdown, channel);
|
send_msg(HotReloadMsg::Shutdown, channel);
|
||||||
}
|
}
|
||||||
@@ -233,11 +234,12 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
|
|||||||
|
|
||||||
// Give time for the change to take effect before reading the file
|
// Give time for the change to take effect before reading the file
|
||||||
if !real_paths.is_empty() {
|
if !real_paths.is_empty() {
|
||||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut channels = channels.lock().unwrap();
|
let mut channels = channels.lock().unwrap();
|
||||||
for path in real_paths {
|
for path in real_paths {
|
||||||
|
println!("File changed: {:?}", path);
|
||||||
// if this file type cannot be hot reloaded, rebuild the application
|
// if this file type cannot be hot reloaded, rebuild the application
|
||||||
if path.extension().and_then(|p| p.to_str()) != Some("rs") {
|
if path.extension().and_then(|p| p.to_str()) != Some("rs") {
|
||||||
rebuild();
|
rebuild();
|
||||||
|
|||||||
Reference in new issue
Block a user