Description Super classes Active bindings Methods See Also
Turbo uses complementary techniques to dramatically reduce the amount of custom JavaScript that most web applications will need to write.
webtools::Configurable
-> webtools::Plugin
-> Turbo
clients
client IDs for turbo websocket connections
new()
Create a new TurboPlugin
Turbo$new( turbo_root = NULL, progress_bar = TRUE, pb_height = "5px", pb_color = "#008080", pb_delay = 500, turbo_opt_in = FALSE, turbo_socket = FALSE, app_version = NA_character_ )
turbo_root
(str) path of the turbo root
progress_bar
(flg) whether progress bar is visible
pb_height
(css) height of progress bar (top)
pb_color
(css) color fo the progress bar
pb_delay
(num) milliseconds before progress bar appears
turbo_opt_in
(flg) if TRUE, then turbo is disabled in the page
turbo_socket
(flg) add the turbo web socket
app_version
(str) a string indicating the version, or NA to disable; used to force reload for new version
assets()
Generates Turbo Assets
Turbo$assets(turbo = TRUE)
turbo
(opt) include turbo assets
TRUE
- include assets with global defaults (default)
FALSE
- do not include turbo assets
list()
- a list that overrides the default config
root (str) path of the turbo root
libs (str) path of the libraries
force_reload (flg) whether this page will force a reload
progress_bar (flg) whether progress bar is visible
pb_height (css) height of progress bar (top)
pb_delay (int) milliseconds of delay before progress bar appears
pb_color (css) color fo the progress bar
cache_control (str) whether to avoid previewing or caching the page
turbo_opt_in (flg) if TRUE, then turbo is disabled across the page
turbo_socket (flg) add the turbo web socket
app_version (str) a string indicating the version, or NA to disable; used to force reload when assets change
router()
Create a Turbo enabled page
Turbo$router(path, handler, ..., turbo = TRUE, lang = NULL, fragment = FALSE)
path
(str) endpoint
handler
(fun) handler; must have arguments
request
, response
, keys
, ...
and
set the body to html tags
...
(arg) passed to self$router_html()
turbo
(opt) include turbo assets
TRUE
- include assets with global defaults (default)
FALSE
- do not include turbo assets
list()
- a list that overrides the default config
root (str) path of the turbo root
libs (str) path of the libraries
force_reload (flg) whether this page will force a reload
progress_bar (flg) whether progress bar is visible
pb_height (css) height of progress bar (top)
pb_delay (int) milliseconds of delay before progress bar appears
pb_color (css) color fo the progress bar
cache_control (str) whether to avoid previewing or caching the page
turbo_opt_in (flg) if TRUE, then turbo is disabled across the page
turbo_socket (flg) add the turbo web socket
app_version (str) a string indicating the version, or NA to disable; used to force reload when assets change
lang
(str) language, defaults to en
.
fragment
(flg) whether to return a full page or fragment
router_stream()
Turbo stream response with defaults
Turbo$router_stream( path, handler, ..., methods = c("get", "post"), type = "text/vnd.turbo-stream.html", lang = NULL, fragment = TRUE )
path
(str) endpoint
handler
(fun) handler; must have arguments
request
, response
, keys
, ...
and
set the body to html tags
...
(arg) passed to self$router_html()
methods
(str) defaults to GET and POST
type
(str) content type, defaults to turbo stream
lang
(str) language, defaults to en
.
fragment
(flg) whether to return a full page or fragment
send()
Send a turbo websocket message
Turbo$send(name, data, id = NULL)
name
(str) name of the turbo message to send
data
(str) data for the event
id
(str) client ID, leave blank to send to all clients
log()
Send a turbo log message
Turbo$log(type, ...)
type
(str) type of the message
...
(chr) components of the message
visit()
Sends a visit turbo event from the server
Turbo$visit(location, action = c("advance", "replace"), id = NULL)
location
(url) location (relative path) to visit
action
(str) either:
advance
(default) - new entry entered into browser history
replace
- replaces the topmost history entry
id
(str) client ID, leave blank to send to all clients
clear()
Clears the Turbo Drive page cache
Turbo$clear(id = NULL)
id
(str) client ID, leave blank to send to all clients
listen()
Add a turbo listener
Turbo$listen( event = c("before-visit", "before-render", "before-fetch-request", "click", "visit", "submit-start", "before-fetch_response", "submit-end", "before-cache", "before-render", "before-stream-render", "render", "load", "frame-render", "frame-load"), code, id = NULL )
event
(str) event to listen for:
before-visit
- before visiting a location, except when navigating
by history.
event.detail.url
contains the URL
before-render
- pause rendering and prepare before fetching;
useful for animations
before-fetch-request
- pause rendering and prepare the request;
useful for attaching information to request.
event.detail.url
contains the URL
event.detail.fetchOptions
contains fetch options
event.target
- the element that triggered it
event.detail.resume()
- resumes the request
click
- when a Turbo-enabled link is clicked
event.detail.url
contains the URL
cancelling will fall through to normal navigation
visit
- immediately after a visit starts
event.detail.url
contains the requested location
event.detail.action
contains the action
submit-start
- form submission
event.detail.formSubmission
- contains the FormSubmission
before-fetch-response
- when the network request completes
event.detail
- contains fetch options
event.target
- contains the firing element
submit-end
- fires after the form submission-initiaited network
request completes.
event.detail.formSubmission
- contains the FormSubmission
event.detail
- FormSubmissionResult
before-cache
- before Turbo saves the current page to cache
before-render
- before rendering the page.
event.detail.newBody
- new body elemetn
event.detail.resume()
- canceling and continuing the rendering
before-stream-render
- fires before a page update is rendered
render
- fires after Turbo renders the page, if the page is cached
then fires both when rendering cached and fresh version.
load
- fires after the initial page load and every visit
event.detail.timing
- visit timings
frame-render
- fires right after a turbo frame renders
event.target
- the frame
event.detail.fetchResponse
- the FetchResponse
object
frame-load
- fires when Turbo frame is after frame-render
event.target
- the frame
code
(str) - JS code to be executed inside the handler.
id
(str) client ID, leave blank to send to all clients
stream()
Send a turbo stream
Turbo$stream( action = c("append", "prepend", "replace", "update", "remove", "before", "after"), target, ..., id = NULL, multiple = FALSE, env = parent.frame() )
action
(str) the action to be taken for this stream element:
append
- inserted last inside the element
prepend
- inserted first inside the element
replace
- replace the whole element
update
- replace the element but keep handlers intact; only HTML
remove
- remove the element
before
- insert before the element
after
- insert after the element
target
(str) target of any links clicked in this:
NULL
- the frame itself
"_top"
- the whole window
"<id>"
- a specific frame outside tof the current frame
...
(tag) tag content of the stream
id
(str) client ID, leave blank to send to all clients
multiple
(flg) if multiple targets, then target
is CSS selector
env
(env) calling environment
clone()
The objects of this class are cloneable with this method.
Turbo$clone(deep = FALSE)
deep
Whether to make a deep clone.
Other Turbo:
turbo_assets()
,
turbo_frame()
,
turbo_link()
,
turbo_listener()
,
turbo_modifiers
,
turbo_stream()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.