mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-07 03:00:20 -04:00
Ensure that callbacks fire in a FIFO order
Version bump required so Leaflet can detect this fix
This commit is contained in:
3
R/map.R
3
R/map.R
@@ -23,6 +23,9 @@ Map <- R6Class(
|
||||
env[[key]] <- value
|
||||
value
|
||||
},
|
||||
mget = function(keys) {
|
||||
base::mget(keys, env)
|
||||
},
|
||||
mset = function(...) {
|
||||
args <- list(...)
|
||||
if (length(args) == 0)
|
||||
|
||||
@@ -580,7 +580,11 @@ Callbacks <- R6Class(
|
||||
})
|
||||
},
|
||||
invoke = function(..., onError=NULL) {
|
||||
for (callback in .callbacks$values()) {
|
||||
# Ensure that calls are invoked in the order that they were registered
|
||||
keys <- as.character(sort(as.integer(.callbacks$keys()), decreasing = TRUE))
|
||||
callbacks <- .callbacks$mget(keys)
|
||||
|
||||
for (callback in callbacks) {
|
||||
if (is.null(onError)) {
|
||||
callback(...)
|
||||
} else {
|
||||
|
||||
@@ -100,3 +100,20 @@ test_that("anyUnnamed works as expected", {
|
||||
x <- x[3:4]
|
||||
expect_true(anyUnnamed(x))
|
||||
})
|
||||
|
||||
test_that("Callbacks fire in predictable order", {
|
||||
cb <- Callbacks$new()
|
||||
|
||||
x <- numeric(0)
|
||||
cb$register(function() {
|
||||
x <<- c(x, 1)
|
||||
})
|
||||
cb$register(function() {
|
||||
x <<- c(x, 2)
|
||||
})
|
||||
cb$register(function() {
|
||||
x <<- c(x, 3)
|
||||
})
|
||||
cb$invoke()
|
||||
expect_equal(x, c(1, 2, 3))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user