Skip to content

Commit 365d8d1

Browse files
committed
vertigo-cli: Added add-watch-path to watch command
1 parent d9ab46a commit 365d8d1

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* `#[js_json(default = "None")]` attribute to `AutoJsJson`
1010
* All http methods in `FetchMethod`
1111
* `history_replace` method in `Driver`
12+
* vertigo-cli: `add-watch-path` to `watch` command
1213

1314
### Fixed
1415

crates/vertigo-cli/src/watch/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use notify::RecursiveMode;
33
use poem::http::Method;
44
use poem::middleware::Cors;
55
use poem::{get, listener::TcpListener, EndpointExt, Route, Server};
6+
use std::path::Path;
67
use std::sync::Arc;
78
use std::time::Duration;
89
use tokio::sync::watch::Sender;
@@ -43,6 +44,10 @@ pub struct WatchOpts {
4344
/// Setting the parameters `--env api=http://domain.com/api --env api2=http://domain.com/api2`
4445
#[arg(long, value_parser = parse_key_val::<String, String>)]
4546
pub env: Vec<(String, String)>,
47+
48+
/// Add more directories to be watched for code changes
49+
#[arg(long)]
50+
pub add_watch_path: Vec<String>,
4651
}
4752

4853
impl WatchOpts {
@@ -171,6 +176,13 @@ pub async fn run(mut opts: WatchOpts) -> Result<(), i32> {
171176

172177
use notify::Watcher;
173178
watcher.watch(&path, RecursiveMode::Recursive).unwrap();
179+
180+
for watch_path in &opts.add_watch_path {
181+
log::info!("Adding `{watch_path}` to watched directories");
182+
watcher
183+
.watch(Path::new(watch_path), RecursiveMode::Recursive)
184+
.expect("Error adding watch dir");
185+
}
174186
let mut version = 0;
175187

176188
loop {

crates/vertigo/src/render/dom_value.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ pub fn render_value_option<T: Clone + PartialEq + 'static>(
1515
let render = render.clone();
1616

1717
move |value| {
18-
let new_element = render(value).map(|new_element| {
18+
let new_element = render(value).inspect(|new_element| {
1919
get_driver().inner.dom.insert_before(
2020
parent_id,
2121
new_element.id_dom(),
2222
Some(comment_id),
2323
);
24-
new_element
2524
});
2625

2726
current_node.change(|current| {

0 commit comments

Comments
 (0)