Created
November 27, 2018 00:03
-
-
Save alandipert/c464e61c89c30b7d3ab0835c275b3e38 to your computer and use it in GitHub Desktop.
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
#' @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