1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/reactive-domains.R
3\name{domains}
4\alias{domains}
5\alias{getDefaultReactiveDomain}
6\alias{withReactiveDomain}
7\alias{onReactiveDomainEnded}
8\title{Reactive domains}
9\usage{
10getDefaultReactiveDomain()
11
12withReactiveDomain(domain, expr)
13
14onReactiveDomainEnded(domain, callback, failIfNull = FALSE)
15}
16\arguments{
17\item{domain}{A valid domain object (for example, a Shiny session), or
18\code{NULL}}
19
20\item{expr}{An expression to evaluate under \code{domain}}
21
22\item{callback}{A callback function to be invoked}
23
24\item{failIfNull}{If \code{TRUE} then an error is given if the \code{domain}
25is \code{NULL}}
26}
27\description{
28Reactive domains are a mechanism for establishing ownership over reactive
29primitives (like reactive expressions and observers), even if the set of
30reactive primitives is dynamically created. This is useful for lifetime
31management (i.e. destroying observers when the Shiny session that created
32them ends) and error handling.
33}
34\details{
35At any given time, there can be either a single "default" reactive domain
36object, or none (i.e. the reactive domain object is \code{NULL}). You can
37access the current default reactive domain by calling
38\code{getDefaultReactiveDomain}.
39
40Unless you specify otherwise, newly created observers and reactive
41expressions will be assigned to the current default domain (if any). You can
42override this assignment by providing an explicit \code{domain} argument to
43\code{\link[=reactive]{reactive()}} or \code{\link[=observe]{observe()}}.
44
45For advanced usage, it's possible to override the default domain using
46\code{withReactiveDomain}. The \code{domain} argument will be made the
47default domain while \code{expr} is evaluated.
48
49Implementers of new reactive primitives can use \code{onReactiveDomainEnded}
50as a convenience function for registering callbacks. If the reactive domain
51is \code{NULL} and \code{failIfNull} is \code{FALSE}, then the callback will
52never be invoked.
53}
54