update docs
This commit is contained in:
1 parent
d642e53a2b
commit
22f86ed464
4 files changed
+45
-25
No files matched your search
@@ -24,6 +24,8 @@ dioxus serve --hot-reload
|
|||||||
For desktop, LiveView, and tui, you can place the hot reload macro at the top of your main function 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.
|
||||||
Hot reloading is automatically enabled on debug builds.
|
Hot reloading is automatically enabled on debug builds.
|
||||||
|
|
||||||
|
For more information about hot reloading on native platforms and configuration options see the [dioxus-hot-reload](https://crates.io/crates/dioxus-hot-reload) crate.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
Add the following to your main function:
|
Add the following to your main function:
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,12 @@
|
|||||||
name = "dioxus-hot-reload"
|
name = "dioxus-hot-reload"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
license = "MIT/Apache-2.0"
|
||||||
|
repository = "https://github.com/DioxusLabs/dioxus/"
|
||||||
|
homepage = "https://dioxuslabs.com"
|
||||||
|
description = "Hot reloading utilites for Dioxus"
|
||||||
|
documentation = "https://dioxuslabs.com"
|
||||||
|
keywords = ["dom", "ui", "gui", "react", "hot-reloading", "watch"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -79,31 +79,32 @@ fn main(){
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
By default the dev server watches on the `src` and `examples` folders in the root crate directory. To watch on custom paths pass the paths into the hot relaod macro:
|
By default the dev server watches on the root of the crate the macro is called in and ignores changes in the `/target` directory and any directories set in the `.gitignore` file in the root directory. To watch on custom paths pass call the `with_paths` function on the config builder:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
fn main(){
|
fn main(){
|
||||||
hot_reload_init!("src", "examples", "assets");
|
hot_reload_init!(Config::new().with_paths(&["src", "examples", "assets"]));
|
||||||
// launch your application
|
// launch your application
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
By default the hot reloading server will output some logs in the console, to disable these logs pass the `disable logging` flag into the macro:
|
By default the hot reloading server will output some logs in the console, to disable these logs call the `with_logging` function on the config builder:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
fn main(){
|
fn main(){
|
||||||
hot_reload_init!("src", "examples", "assets", disable logging);
|
hot_reload_init!(Config::new().with_logging(false));
|
||||||
// launch your application
|
// 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 resultsing 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 macro 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:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
fn main(){
|
fn main(){
|
||||||
hot_reload_init!(@MyNamespace /*more configeration*/);
|
// Note: Use default instead of new if you are using a custom namespace
|
||||||
|
hot_reload_init!(Config::<MyContext>::default());
|
||||||
// launch your application
|
// launch your application
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -118,15 +119,22 @@ async fn launch(app: Component) {
|
|||||||
// ...
|
// ...
|
||||||
|
|
||||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
dioxus_hot_reload::connect(move |template| {
|
dioxus_hot_reload::connect(move |msg| {
|
||||||
let _ = tx.send(template);
|
let _ = tx.send(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
Some(template) = rx.recv() => {
|
Some(msg) = rx.recv() => {
|
||||||
// update the template in the virtual dom
|
match msg{
|
||||||
vdom.replace_template(template);
|
HotReloadMsg::Shutdown => {
|
||||||
|
// ... shutdown the application
|
||||||
|
}
|
||||||
|
HotReloadMsg::UpdateTemplate(template) => {
|
||||||
|
// update the template in the virtual dom
|
||||||
|
vdom.replace_template(template);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ = vdom.wait_for_work() => {
|
_ = vdom.wait_for_work() => {
|
||||||
// ...
|
// ...
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ impl Config<HtmlCtx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Ctx: HotReloadingContext> Config<Ctx> {
|
impl<Ctx: HotReloadingContext> Config<Ctx> {
|
||||||
|
/// Set the root path of the project (where the Cargo.toml file is). This is automatically set by the [`hot_reload_init`] macro.
|
||||||
pub const fn root(self, path: &'static str) -> Self {
|
pub const fn root(self, path: &'static str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
root_path: path,
|
root_path: path,
|
||||||
@@ -71,24 +72,30 @@ impl<Ctx: HotReloadingContext> Config<Ctx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn listening_paths(self, paths: &'static [&'static str]) -> Self {
|
/// Set whether to enable logs
|
||||||
Self {
|
pub const fn with_logging(self, log: bool) -> Self {
|
||||||
listening_paths: paths,
|
|
||||||
..self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn log(self, log: bool) -> Self {
|
|
||||||
Self { log, ..self }
|
Self { log, ..self }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn rebuild_with(self, rebuild_with: &'static str) -> Self {
|
/// 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`
|
||||||
|
pub const fn with_rebuild_handler(self, rebuild_with: &'static str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
rebuild_with: Some(rebuild_with),
|
rebuild_with: Some(rebuild_with),
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the paths to listen for changes in to trigger hot reloading. If this is a directory it will listen for changes in all files in that directory recursively.
|
||||||
|
pub const fn with_paths(self, paths: &'static [&'static str]) -> Self {
|
||||||
|
Self {
|
||||||
|
listening_paths: paths,
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets paths to ignore changes on. This will override any paths set in the [`Config::with_paths`] method in the case of conflicts.
|
||||||
pub const fn excluded_paths(self, paths: &'static [&'static str]) -> Self {
|
pub const fn excluded_paths(self, paths: &'static [&'static str]) -> Self {
|
||||||
Self {
|
Self {
|
||||||
excluded_paths: paths,
|
excluded_paths: paths,
|
||||||
@@ -313,10 +320,7 @@ pub fn connect(mut f: impl FnMut(HotReloadMsg) + Send + 'static) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start the hot reloading server
|
/// Start the hot reloading server with the current directory as the root
|
||||||
///
|
|
||||||
/// 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.
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! hot_reload_init {
|
macro_rules! hot_reload_init {
|
||||||
() => {
|
() => {
|
||||||
|
|||||||
Reference in new issue
Block a user