From 82048737f4a1b2fece22b92ae70b97d6dc409c7d Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 12 Jan 2023 08:47:33 -0600 Subject: [PATCH] fix the macro export and WIP hot reloading docs --- docs/guide/src/en/SUMMARY.md | 2 +- .../src/en/getting_started/hot_reload.md | 49 ++++++++++++++++--- packages/dioxus/Cargo.toml | 4 +- packages/dioxus/src/lib.rs | 3 ++ packages/hot-reload/src/lib.rs | 4 +- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/docs/guide/src/en/SUMMARY.md b/docs/guide/src/en/SUMMARY.md index 83840fe90..f9f31ed52 100644 --- a/docs/guide/src/en/SUMMARY.md +++ b/docs/guide/src/en/SUMMARY.md @@ -5,11 +5,11 @@ - [Getting Started](getting_started/index.md) - [Desktop](getting_started/desktop.md) - [Web](getting_started/web.md) - - [Hot Reload](getting_started/hot_reload.md) - [Server-Side Rendering](getting_started/ssr.md) - [Liveview](getting_started/liveview.md) - [Terminal UI](getting_started/tui.md) - [Mobile](getting_started/mobile.md) + - [Hot Reloading](getting_started/hot_reload.md) - [Describing the UI](describing_ui/index.md) - [Special Attributes](describing_ui/special_attributes.md) - [Components](describing_ui/components.md) diff --git a/docs/guide/src/en/getting_started/hot_reload.md b/docs/guide/src/en/getting_started/hot_reload.md index 823baa179..8c4d4310d 100644 --- a/docs/guide/src/en/getting_started/hot_reload.md +++ b/docs/guide/src/en/getting_started/hot_reload.md @@ -2,20 +2,53 @@ 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. -3. Currently the cli only implements hot reloading for the web renderer. +3. Currently the cli only implements hot reloading for the web renderer. For TUI, desktop, and liveview you can use the hot reload macro. + +# Web + +For the web renderer, you can use the dioxus cli to serve your application with hot reloading enabled. + +## Setup -# Setup Install [dioxus-cli](https://github.com/DioxusLabs/cli). Hot reloading is automatically enabled when using the web renderer on debug builds. -# Usage -1. run: -``` +## Usage + +1. Run: +```bash dioxus serve --hot-reload ``` -2. change some code within a rsx macro -3. open your localhost in a browser -4. save and watch the style change without recompiling +2. Change some code within a rsx or render macro +3. Open your localhost in a browser +4. Save and watch the style change without recompiling + +# Desktop/Liveview/TUI + +For desktop, LiveView, and tui, you can place the hot reload macro before your app runs to enable hot reloading. + +## Setup + +Add the following to your main function: + +```rust +fn main() { + dioxus::hot_reload_init!(); + // launch your application +} +``` + +## Usage +1. Run: +```bash +cargo run +``` +2. Change some code within a rsx or render macro +3. Save and watch the style change without recompiling + +## Custom renders + +For custom renderers # 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. diff --git a/packages/dioxus/Cargo.toml b/packages/dioxus/Cargo.toml index ceab90a1b..0360b207f 100644 --- a/packages/dioxus/Cargo.toml +++ b/packages/dioxus/Cargo.toml @@ -17,12 +17,14 @@ dioxus-html = { path = "../html", version = "^0.3.0", optional = true } dioxus-core-macro = { path = "../core-macro", version = "^0.3.0", optional = true } dioxus-hooks = { path = "../hooks", version = "^0.3.0", optional = true } dioxus-rsx = { path = "../rsx", version = "0.0.2", optional = true } +dioxus-hot-reload = { path = "../hot-reload", version = "0.1.0", optional = true } [features] -default = ["macro", "hooks", "html"] +default = ["macro", "hooks", "html", "hot-reload"] macro = ["dioxus-core-macro", "dioxus-rsx"] html = ["dioxus-html"] hooks = ["dioxus-hooks"] +hot-reload = ["dioxus-hot-reload"] [dev-dependencies] diff --git a/packages/dioxus/src/lib.rs b/packages/dioxus/src/lib.rs index fed3d2bd5..fe181bf14 100644 --- a/packages/dioxus/src/lib.rs +++ b/packages/dioxus/src/lib.rs @@ -31,4 +31,7 @@ pub mod prelude { #[cfg(feature = "html")] pub use dioxus_elements::{prelude::*, GlobalAttributes, SvgAttributes}; + + #[cfg(feature = "hot-reload")] + pub use dioxus_hot_reload::hot_reload_init; } diff --git a/packages/hot-reload/src/lib.rs b/packages/hot-reload/src/lib.rs index 586c3c95b..6ac5c2c35 100644 --- a/packages/hot-reload/src/lib.rs +++ b/packages/hot-reload/src/lib.rs @@ -152,7 +152,7 @@ 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. /// If no paths are passed, it will listen on the src and examples folders. #[macro_export] -macro_rules! hot_reload { +macro_rules! hot_reload_init_inner { () => { dioxus_hot_reload::init(core::env!("CARGO_MANIFEST_DIR"), &["src", "examples"]) }; @@ -161,3 +161,5 @@ macro_rules! hot_reload { dioxus_hot_reload::init(core::env!("CARGO_MANIFEST_DIR"), &[$($paths),*]) }; } + +pub use hot_reload_init_inner as hot_reload_init;