Skip to content

Commit

Permalink
Admin, hot reload, bug fixes, template features, docs (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
levkk authored Oct 31, 2024
1 parent 7e96a15 commit 0660607
Show file tree
Hide file tree
Showing 45 changed files with 1,095 additions and 40 deletions.
182 changes: 169 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ members = [
"rwf-macros",
"rwf-tests",
"examples/django",
"examples/request-tracking", "examples/engine",
"examples/request-tracking",
"examples/engine",
"rwf-admin",
]
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.md.bak
1 change: 1 addition & 0 deletions docs/docs/.pages
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ nav:
- 'views'
- 'configuration.md'
- 'background-jobs'
- 'user-guides'
- '...'
36 changes: 36 additions & 0 deletions docs/docs/user-guides/hot-reload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Hot reload

Hot reload, also known as hot module replacement (HMR), is a technique for automatically replacing frontend components that changed during local development, without the developer having to reload the page manually.
While Rwf [templates](../views/templates/index.md) don't use JavaScript frameworks like React or Vue, they do support being reloaded automatically.


## Enable hot reload

To enable template hot reloading, make sure your application is using [Turbo Streams](../views/turbo/streams.md). The page refresh event is delivered from the server using a WebSocket connection.

Current hot reload implementation works best if you are storing your templates in one directory, e.g. `templates`. To enable HMR, launch it before launching the HTTP server:

```rust
use rwf::hmr::hmr;

use std::path::PathBuf;

#[tokio::main]
async fn main() {
// Enable HMR notifications for any changes
// to the `templates` directory.
hmr(PathBuf::from("templates"));

/* ... */
}
```

When editing templates with your favorite text editor, Rwf will send an event via the Turbo Stream connection which will reload the page every time a template file is saved. Since Turbo makes page reloads seamless, this simulates the behavior of HMR used by frameworks like React or Vue.

### Debug only

HMR only makes sense in development, so the functionality is available in `debug` builds which are used by default when you use `cargo run`. In `release` builds, HMR is disabled.

## Learn more

- [rwf-admin](https://github.com/levkk/rwf/blob/main/rwf-admin/src/main.rs) uses HMR
Loading

0 comments on commit 0660607

Please sign in to comment.