mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-17 06:08:26 +00:00
update docs
This commit is contained in:
parent
d642e53a2b
commit
22f86ed464
4 changed files with 45 additions and 25 deletions
|
@ -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.
|
||||
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
|
||||
Add the following to your main function:
|
||||
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
name = "dioxus-hot-reload"
|
||||
version = "0.1.0"
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
fn main(){
|
||||
hot_reload_init!("src", "examples", "assets");
|
||||
hot_reload_init!(Config::new().with_paths(&["src", "examples", "assets"]));
|
||||
// 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
|
||||
fn main(){
|
||||
hot_reload_init!("src", "examples", "assets", disable logging);
|
||||
hot_reload_init!(Config::new().with_logging(false));
|
||||
// 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
|
||||
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
|
||||
}
|
||||
```
|
||||
|
@ -118,15 +119,22 @@ async fn launch(app: Component) {
|
|||
// ...
|
||||
|
||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
dioxus_hot_reload::connect(move |template| {
|
||||
let _ = tx.send(template);
|
||||
dioxus_hot_reload::connect(move |msg| {
|
||||
let _ = tx.send(msg);
|
||||
});
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
Some(template) = rx.recv() => {
|
||||
// update the template in the virtual dom
|
||||
vdom.replace_template(template);
|
||||
Some(msg) = rx.recv() => {
|
||||
match msg{
|
||||
HotReloadMsg::Shutdown => {
|
||||
// ... shutdown the application
|
||||
}
|
||||
HotReloadMsg::UpdateTemplate(template) => {
|
||||
// update the template in the virtual dom
|
||||
vdom.replace_template(template);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ = vdom.wait_for_work() => {
|
||||
// ...
|
||||
|
|
|
@ -64,6 +64,7 @@ impl Config<HtmlCtx> {
|
|||
}
|
||||
|
||||
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 {
|
||||
Self {
|
||||
root_path: path,
|
||||
|
@ -71,24 +72,30 @@ impl<Ctx: HotReloadingContext> Config<Ctx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn listening_paths(self, paths: &'static [&'static str]) -> Self {
|
||||
Self {
|
||||
listening_paths: paths,
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn log(self, log: bool) -> Self {
|
||||
/// Set whether to enable logs
|
||||
pub const fn with_logging(self, log: bool) -> 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 {
|
||||
rebuild_with: Some(rebuild_with),
|
||||
..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 {
|
||||
Self {
|
||||
excluded_paths: paths,
|
||||
|
@ -313,10 +320,7 @@ pub fn connect(mut f: impl FnMut(HotReloadMsg) + Send + 'static) {
|
|||
});
|
||||
}
|
||||
|
||||
/// Start the hot reloading server
|
||||
///
|
||||
/// 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.
|
||||
/// Start the hot reloading server with the current directory as the root
|
||||
#[macro_export]
|
||||
macro_rules! hot_reload_init {
|
||||
() => {
|
||||
|
|
Loading…
Add table
Reference in a new issue