Skip to content

Commit 35ec809

Browse files
author
Ryan Patrick Kyle
committed
🔨 properly detect changes recursively
1 parent 8b34a1f commit 35ec809

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

R/dash.R

+13-5
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,11 @@ Dash <- R6::R6Class(
614614
# this calls getAppPath, which will try three approaches to
615615
# identifying the local app path (depending on whether the app
616616
# is invoked via script, source(), or executed directly from console)
617-
private$app_root_modtime <- modtimeFromPath(private$app_root_path)
617+
private$app_root_modtime <- as.integer(
618+
max(
619+
file.info(
620+
list.files(getAppPath(),
621+
recursive=TRUE))$mtime))
618622

619623
if (is.null(dev_tools_ui) && debug || isTRUE(dev_tools_ui)) {
620624
self$config$ui <- TRUE
@@ -653,11 +657,13 @@ Dash <- R6::R6Class(
653657
if (self$config$hot_reload == TRUE && file.exists(file.path(getAppPath(), "assets"))) {
654658
self$server$on('cycle-end', function(server, ...) {
655659
current_asset_modtime <- modtimeFromPath(private$assets_folder)
656-
current_root_modtime <- modtimeFromPath(getAppPath())
657-
660+
current_root_modtime <- modtimeFromPath(getAppPath(), recursive = TRUE)
661+
658662
updated_assets <- isTRUE(current_asset_modtime > private$asset_modtime)
659663
updated_root <- isTRUE(current_root_modtime > private$app_root_modtime)
660-
664+
665+
private$app_root_modtime <- current_root_modtime
666+
661667
initiate_reload <- isTRUE((as.integer(Sys.time()) - private$last_reload) > self$config$hot_reload_interval)
662668

663669
if (!is.null(private$asset_modtime) && initiate_reload && (updated_assets || updated_root)) {
@@ -669,7 +675,6 @@ Dash <- R6::R6Class(
669675
private$modified_since_reload <- updatedFiles$modified
670676

671677
private$asset_modtime <- current_asset_modtime
672-
private$app_root_modtime <- current_root_modtime
673678
# update the hash passed back to the renderer, and bump the timestamp
674679
# to match the current reloading event
675680
private$updateReloadHash()
@@ -702,7 +707,10 @@ Dash <- R6::R6Class(
702707
})
703708

704709
if (!self$config$running && file.exists(file.path(getAppPath(), "app.R")))
710+
{
705711
source(file.path(getAppPath(), "app.R"))
712+
private$index()
713+
}
706714
else {
707715
self$config$running <- TRUE
708716
self$server$ignite(block = block, showcase = showcase, ...)

R/utils.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,12 @@ getIdProps <- function(output) {
917917
return(list(ids=ids, props=props))
918918
}
919919

920-
modtimeFromPath <- function(path) {
921-
modtime <- as.integer(file.info(path)$mtime)
920+
modtimeFromPath <- function(path, recursive=FALSE) {
921+
if (recursive) {
922+
modtime <- as.integer(max(file.info(list.files(path, recursive=TRUE))$mtime))
923+
} else {
924+
modtime <- as.integer(file.info(path)$mtime)
925+
}
922926
return(modtime)
923927
}
924928

0 commit comments

Comments
 (0)