Skip to content

Commit

Permalink
move extract_landing and drop_landing into modules.R
Browse files Browse the repository at this point in the history
  • Loading branch information
m7pr committed Oct 23, 2023
1 parent a0e2ce2 commit 5b34678
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
23 changes: 0 additions & 23 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,29 +138,6 @@ init <- function(data,
modules <- do.call(teal::modules, modules)
}

# move these two functions to utils.R or modules.R
# maybe combine into one function?
extract_landing <- function(modules) {
if (inherits(modules, "landing_module")) {
modules
} else if (inherits(modules, "teal_module")) {
NULL
} else if (inherits(modules, "teal_modules")) {
Filter(function(x) length(x) > 0L, lapply(modules$children, extract_landing))
}
}
drop_landing <- function(modules) {
if (inherits(modules, "landing_module")) {
NULL
} else if (inherits(modules, "teal_module")) {
modules
} else if (inherits(modules, "teal_modules")) {
do.call(
"modules",
c(Filter(function(x) length(x) > 0L, lapply(modules$children, drop_landing)), label = modules$label)
)
}
}
landing <- extract_landing(modules)
modules <- drop_landing(modules)

Expand Down
30 changes: 30 additions & 0 deletions R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ append_module <- function(modules, module) {
modules
}

#' Extract a `landing_module` from list of `modules`
#' @param modules `teal_modules`
#' @keywords internal
#' @return `landing_module`
extract_landing <- function(modules) {
if (inherits(modules, "landing_module")) {
modules
} else if (inherits(modules, "teal_module")) {
NULL
} else if (inherits(modules, "teal_modules")) {
Filter(function(x) length(x) > 0L, lapply(modules$children, extract_landing))
}
}
#' Remove a `landing_module` from list of `modules`
#' @param modules `teal_modules`
#' @keywords internal
#' @return `teal_modules`
drop_landing <- function(modules) {
if (inherits(modules, "landing_module")) {
NULL
} else if (inherits(modules, "teal_module")) {
modules
} else if (inherits(modules, "teal_modules")) {
do.call(
"modules",
c(Filter(function(x) length(x) > 0L, lapply(modules$children, drop_landing)), label = modules$label)
)
}
}

#' Does the object make use of the `arg`
#'
#' @param modules (`teal_module` or `teal_modules`) object
Expand Down

0 comments on commit 5b34678

Please sign in to comment.