-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(targetting): converted to actions
* The targetting feature is now better named `actions`. (#166)
- Loading branch information
nteetor
committed
Nov 26, 2019
1 parent
6cc8bbf
commit 5cb19c8
Showing
7 changed files
with
138 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#' Input actions | ||
#' | ||
#' These functions are used in conjunction with the `targets` argument found | ||
#' in all of yonder's reactive input functions. | ||
#' | ||
#' @param id A character string specifying the id of a [navPane()] or | ||
#' [collapsePane()]. | ||
#' | ||
#' @param ... Additional arguments, currently ignored. | ||
#' | ||
#' @name actions | ||
NULL | ||
|
||
#' @rdname actions | ||
#' @export | ||
showTarget <- function(id, ...) { | ||
create_targeter("show", id) | ||
} | ||
|
||
#' @rdname actions | ||
#' @export | ||
hideTarget <- function(id, ...) { | ||
create_targeter("hide", id) | ||
} | ||
|
||
create_targeter <- function(action, id) { | ||
structure( | ||
class = c("targeter", "list"), | ||
list( | ||
action = action, | ||
target = id | ||
) | ||
) | ||
} | ||
|
||
is_targeter <- function(x) { | ||
inherits(x, "targeter") | ||
} | ||
|
||
#' Explain a targetting action | ||
#' | ||
#' Printing a targetting action displays a message about the action performed. | ||
#' | ||
#' @param x An object with class `"targeter"`. | ||
#' | ||
#' @param ... Additional arguments passed on to other methods. | ||
#' | ||
#' @keywords internal | ||
#' @export | ||
print.targeter <- function(x, ...) { | ||
msg <- "Selecting the input choice with the corresponding value _%s_ the element with id `%s`" | ||
cat(sprintf(msg, x$action, x$id), "\n") | ||
invisible(x) | ||
} | ||
|
||
construct_targets <- function(targets, values) { | ||
if (is.null(targets)) { | ||
return(targets) | ||
} | ||
|
||
if (length(targets) > 1) { | ||
targets <- lapply(targets, function(target) { | ||
if (is.character(target)) { | ||
paste0("#", target, collapse = " ") | ||
} else if (is_targeter(target)) { | ||
stop("Not implemented") | ||
} | ||
}) | ||
|
||
if (all(names2(targets) == "")) { | ||
names(targets) <- values | ||
} | ||
|
||
targets | ||
} else if (is.character(targets)) { | ||
targets | ||
} | ||
} | ||
|
||
get_target <- function(targets, value) { | ||
if (is.null(targets)) { | ||
NULL | ||
} else if (is.character(targets)) { | ||
paste0("#", value) | ||
} else { | ||
targets[[value]] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.