Skip to content

Commit

Permalink
change extract/drop_landing into extract/drop_module with class argument
Browse files Browse the repository at this point in the history
  • Loading branch information
m7pr committed Oct 23, 2023
1 parent 881d88f commit 69d5c71
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 29 deletions.
4 changes: 2 additions & 2 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ init <- function(data,
modules <- do.call(teal::modules, modules)
}

landing <- extract_landing(modules)
landing <- extract_module(modules, "teal_module_landing")
if (length(landing) > 1L) stop("teal only supports apps with one module of `tm_landing_popup` class.")
modules <- drop_landing(modules)
modules <- drop_module(modules, "teal_module_landing")

# resolve modules datanames
datanames <- teal.data::get_dataname(data)
Expand Down
11 changes: 1 addition & 10 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,7 @@ srv_teal <- function(id, modules, raw_data, filter = teal_slices()) {
})

reporter <- teal.reporter::Reporter$new()
is_any_previewer <- function(modules) {
if (inherits(modules, "teal_modules")) {
any(unlist(lapply(modules$children, is_any_previewer), use.names = FALSE))
} else if (inherits(modules, "teal_module_previewer")) {
TRUE
} else {
FALSE
}
}
if (is_arg_used(modules, "reporter") && !is_any_previewer(modules)) {
if (is_arg_used(modules, "reporter") && length(extract_module(modules, 'teal_module_previewer')) == 0) {

Check warning on line 229 in R/module_teal.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/module_teal.R,line=229,col=76,[quotes_linter] Only use double-quotes.
modules <- append_module(modules, reporter_previewer_module())
}

Expand Down
15 changes: 8 additions & 7 deletions R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,26 @@ append_module <- function(modules, module) {
modules
}

#' Extract a `teal_module_landing` from list of `modules`
#' Extract specific class from a list of `modules`
#' @param modules `teal_modules`
#' @keywords internal
#' @return `teal_module_landing`
extract_landing <- function(modules) {
if (inherits(modules, "teal_module_landing")) {
extract_module <- function(modules, class) {
if (inherits(modules, class)) {
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))
Filter(function(x) length(x) > 0L, lapply(modules$children, extract_module))
}
}
#' Remove a `teal_module_landing` from list of `modules`

#' Remove a specific class from list of `modules`
#' @param modules `teal_modules`
#' @keywords internal
#' @return `teal_modules`
drop_landing <- function(modules) {
if (inherits(modules, "teal_module_landing")) {
drop_module <- function(modules, class) {
if (inherits(modules, class)) {
NULL
} else if (inherits(modules, "teal_module")) {
modules
Expand Down
10 changes: 5 additions & 5 deletions man/drop_landing.Rd → man/drop_module.Rd

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

10 changes: 5 additions & 5 deletions man/extract_landing.Rd → man/extract_module.Rd

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

0 comments on commit 69d5c71

Please sign in to comment.