Description Usage Arguments Value Examples
Dispatcher Constructor.
1 2 3 4 5 | dispatcher(handlers)
new_dispatcher(handlers)
validate_dispatcher(handlers)
|
handlers |
A list of handlers build using handler() function. |
The dispatcher()
function retuns a dispatcher
object. A
dispatcher
object contains two items: handlers
and dispatch
.
handlers
is a handlers_list
object with all the handlers definitions.
dispatch
is a function with two params: obj and event. The dispatch()
function allows the user to run a list of events using the handlers definitions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | library(eventr)
library(dplyr)
birth_event <- event(
id = 'first-id',
type = 'BIRTH',
time = '1936-11-09',
birth_date = '1936-11-09'
)
death_event <- event(
id = 'second-id',
type = 'DEATH',
time = '2019-05-22',
death_date = '2019-05-22'
)
set_birth_date <- function(obj, event){
obj$birth_date <- get_body_attr(event, "birth_date")
return(obj)
}
set_death_date <- function(obj, event){
obj$death_date <- get_body_attr(event, "death_date")
return(obj)
}
birth_handler <- handler(type = 'BIRTH', FUN = set_birth_date)
death_handler <- handler(type = 'DEATH', FUN = set_death_date)
handlers <- handlers_list(birth_handler, death_handler)
the_dispatcher <- dispatcher(handlers)
dispatch <- get_dispatch(the_dispatcher)
events <- event_list(birth_event, death_event)
the_obj <- dispatch(events = events, accumulate = FALSE)
the_obj
the_obj <- dispatch(events = events, accumulate = TRUE)
the_obj
# transform the_obj to data.frame
the_obj %>%
purrr::map(as.data.frame) %>%
bind_rows
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.