Skip to content

Commit 4822fa0

Browse files
add mobx dependency function html_dependency_mobx()
1 parent 9001073 commit 4822fa0

File tree

11 files changed

+644
-1
lines changed

11 files changed

+644
-1
lines changed

DESCRIPTION

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ Package: reactR
22
Type: Package
33
Title: React Helpers
44
Version: 0.4.1
5-
Date: 2019-05-14
5+
Date: 2019-07-03
66
Authors@R: c(
77
person(
88
"Facebook", "Inc"
99
, role = c("aut", "cph")
1010
, comment = "React library in lib, https://facebook.github.io/react; see AUTHORS for full list of contributors"
1111
),
12+
person(
13+
"Michel","Weststrate",
14+
, role = c("aut", "cph")
15+
, comment = "mobx library in lib, https://github.com/mobxjs"
16+
),
1217
person(
1318
"Kent", "Russell"
1419
, role = c("aut", "cre")

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export(babel_transform)
99
export(component)
1010
export(createReactShinyInput)
1111
export(html_dependency_corejs)
12+
export(html_dependency_mobx)
1213
export(html_dependency_react)
1314
export(html_dependency_reacttools)
1415
export(reactMarkup)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
* Update react to `16.8.6`
88

9+
* Add `mobx` dependencies available through `html_dependency_mobx()`
10+
911
# reactR 0.4.0
1012

1113
* Add Shiny input scaffold and functionality; [tutorial](https://react-r.github.io/reactR/articles/intro_inputs.html) and [pull 22](https://github.com/react-R/reactR/pull/22) thanks @alandipert

R/dependencies.R

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,78 @@ html_dependency_reacttools <- function(){
8585
script = c("react-tools.js")
8686
)
8787
}
88+
89+
#' Dependencies for 'mobx'
90+
#'
91+
#' Add JavaScript 'mobx' and 'mobx-react' dependency. When using with 'react', the order
92+
#' of the dependencies is important, so please add \code{html_dependency_react()} before
93+
#' \code{html_dependency_mobx()}.
94+
#'
95+
#' @param react \code{logical} to add react 'mobx' dependencies.
96+
#'
97+
#' @return \code{\link[htmltools]{htmlDependency}}
98+
#' @importFrom htmltools htmlDependency
99+
#' @export
100+
#'
101+
#' @examples
102+
#' library(htmltools)
103+
#' library(reactR)
104+
#'
105+
#' browsable(
106+
#' tagList(
107+
#' html_dependency_mobx(react = FALSE),
108+
#' div(id="test"),
109+
#' tags$script(HTML(
110+
#' "
111+
#' var obs = mobx.observable({val: null})
112+
#' mobx.autorun(function() => {
113+
#' document.querySelector('#test').innerText = obs.val
114+
#' })
115+
#' setInterval(
116+
#' function() {obs.val++},
117+
#' 1000
118+
#' )
119+
#' "
120+
#' ))
121+
#' )
122+
#' )
123+
#'
124+
#' # use with react
125+
#' library(htmltools)
126+
#' library(reactR)
127+
#'
128+
#' browsable(
129+
#' tagList(
130+
#' html_dependency_react(),
131+
#' html_dependency_mobx(),
132+
#' div(id="test"),
133+
#' tags$script(HTML(babel_transform(
134+
#' "
135+
#' var obs = mobx.observable({val: null})
136+
#' var App = mobxReact.observer((props) => <div>{props.obs.val}</div>)
137+
#'
138+
#' ReactDOM.render(<App obs = {obs}/>, document.querySelector('#test'))
139+
#'
140+
#' setInterval(
141+
#' function() {obs.val++},
142+
#' 1000
143+
#' )
144+
#' "
145+
#' )))
146+
#' )
147+
#' )
148+
149+
html_dependency_mobx <- function(react = TRUE){
150+
hd <- htmltools::htmlDependency(
151+
name = "mobx",
152+
version = "4.11.0",
153+
src = system.file("www/mobx",package="reactR"),
154+
script = c("mobx.umd.min.js")
155+
)
156+
157+
if(react) {
158+
hd$script <- c(hd$script,"mobx-react-lite.js", "mobx-react.umd.js")
159+
}
160+
161+
hd
162+
}

inst/www/mobx/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Michel Weststrate
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)