Skip to content

Commit 6131677

Browse files
author
Ryan Patrick Kyle
committed
💩 simplify param logic
1 parent aa1ad07 commit 6131677

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

R/dash.R

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -647,21 +647,28 @@ Dash <- R6::R6Class(
647647
}
648648

649649
getServerParam <- function(value, type, default) {
650+
if (toupper(value) %in% c("TRUE", "FALSE"))
651+
value <- as.logical(toupper(value))
650652
if (value != "" && length(value) != 0 && mode(value) == type && !is.na(value)) {
651653
return(value)
652654
} else {
653655
return(default)
654656
}
655657
}
656-
658+
659+
debug <- getServerParam(debug, "logical", FALSE)
660+
private$debug <- debug
661+
657662
self$server$host <- getServerParam(host, "character", "127.0.0.1")
658663
self$server$port <- getServerParam(as.integer(port), "numeric", 8050)
659664

660-
dev_tools_ui <- getServerParam(dev_tools_ui, "logical", NULL)
661-
dev_tools_props_check <- getServerParam(dev_tools_props_check, "logical", NULL)
662-
663-
debug <- getServerParam(debug, "logical", FALSE)
664-
665+
dev_tools_ui <- getServerParam(dev_tools_ui, "logical", debug)
666+
dev_tools_props_check <- getServerParam(dev_tools_props_check, "logical", debug)
667+
dev_tools_silence_routes_logging <- getServerParam(dev_tools_silence_routes_logging, "logical", debug)
668+
dev_tools_hot_reload <- getServerParam(dev_tools_hot_reload, "logical", debug)
669+
670+
private$prune_errors <- getServerParam(dev_tools_prune_errors, "logical", TRUE)
671+
665672
if(getAppPath() != FALSE) {
666673
source_dir <- dirname(getAppPath())
667674
private$app_root_modtime <- modtimeFromPath(source_dir, recursive = TRUE, asset_path = private$assets_folder)
@@ -673,13 +680,9 @@ Dash <- R6::R6Class(
673680
# this calls getAppPath, which will try three approaches to
674681
# identifying the local app path (depending on whether the app
675682
# is invoked via script, source(), or executed dire ctly from console)
676-
if (is.null(dev_tools_ui) && debug || isTRUE(dev_tools_ui)) {
677-
self$config$ui <- TRUE
678-
} else {
679-
self$config$ui <- FALSE
680-
}
683+
self$config$ui <- dev_tools_ui
681684

682-
if (is.null(dev_tools_hot_reload) && debug || isTRUE(dev_tools_hot_reload)) {
685+
if (dev_tools_hot_reload) {
683686
hot_reload <- TRUE
684687
hot_reload_interval <- getServerParam(dev_tools_hot_reload_interval, "numeric", 3)
685688
hot_reload_watch_interval <- getServerParam(dev_tools_hot_reload_watch_interval, "numeric", 0.5)
@@ -690,20 +693,8 @@ Dash <- R6::R6Class(
690693
hot_reload <- FALSE
691694
}
692695

693-
if (is.null(dev_tools_silence_routes_logging) && debug || isTRUE(dev_tools_silence_routes_logging)) {
694-
self$config$silence_routes_logging <- TRUE
695-
} else {
696-
self$config$silence_routes_logging <- FALSE
697-
}
698-
699-
if (is.null(dev_tools_props_check) && debug || isTRUE(dev_tools_props_check)) {
700-
self$config$props_check <- TRUE
701-
} else {
702-
self$config$props_check <- FALSE
703-
}
704-
705-
private$prune_errors <- getServerParam(dev_tools_prune_errors, "logical", TRUE)
706-
private$debug <- debug
696+
self$config$silence_routes_logging <- dev_tools_silence_routes_logging
697+
self$config$props_check <- dev_tools_props_check
707698

708699
if (hot_reload == TRUE & !(is.null(source_dir))) {
709700
self$server$on('cycle-end', function(server, ...) {

0 commit comments

Comments
 (0)