Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created November 27, 2018 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/c464e61c89c30b7d3ab0835c275b3e38 to your computer and use it in GitHub Desktop.
Save alandipert/c464e61c89c30b7d3ab0835c275b3e38 to your computer and use it in GitHub Desktop.
#' @export
React <- structure(list(), class = "react.component.builder")
isUpper <- function(s) {
grepl("^[[:upper:]]+$", s)
}
#' @export
`$.react.component.builder` <- function(x, name) {
if (length(name) == 0 || !isUpper(substring(name, 1, 1))) {
stop("Component name must be specified and start with an upper case character")
}
function(...) {
htmltools::tag(name, list(...))
}
}
#' @export
`[[.react.component.builder` <- `$.react.component.builder`
#' @export
`$<-.react.component.builder` <- function(x, name, value) {
stop("Assigning to a component constructor is not allowed")
}
#' @export
`[[<-.react.component.builder` <- `$<-.react.component.builder`
# Example:
# React$SomeComponent(x = 1,
# React$OtherThing(y = 4),
# React$OtherThing(y = 4),
# )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment