@@ -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+ }
0 commit comments