Skip to content

Commit fc4f6d8

Browse files
committed
refactor: Replace as_top_level() workaround
1 parent 6634af1 commit fc4f6d8

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

R/app.R

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,29 @@ load_main_module <- function() {
4444
}
4545

4646
as_top_level <- function(app_env) {
47-
# Necessary to avoid infinite recursion / bugs due to lazy evaluation:
48-
# https://adv-r.hadley.nz/function-factories.html?q=force#forcing-evaluation
49-
force(app_env)
47+
list(
48+
# Wrap the UI in a function to support Shiny bookmarking.
49+
ui = function(request) app_env$main$ui("app"),
50+
server = fix_server_reloading(function(input, output) {
51+
app_env$main$server("app")
52+
})
53+
)
54+
}
55+
56+
fix_server_reloading <- function(server) {
57+
reparse(curly_wrap(server))
58+
}
5059

51-
# The actual function must be sourced with `keep.source = TRUE` for reloading to work:
52-
# https://github.com/Appsilon/rhino/issues/157
53-
wrap <- source(fs::path_package("rhino", "as_top_level.R"), keep.source = TRUE)$value
60+
reparse <- function(f) {
61+
eval(parse(text = deparse(f)), envir = environment(f))
62+
}
5463

55-
wrap(app_env)
64+
curly_wrap <- function(f) {
65+
wrapped <- function() {
66+
do.call(f, as.list(match.call())[-1])
67+
}
68+
formals(wrapped) <- formals(f)
69+
wrapped
5670
}
5771

5872
load_app <- function() {

inst/as_top_level.R

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)