vw_handler_add_effect: Add a side-effect to a JavaScript handler

View source: R/js-handler.R

vw_handler_add_effectR Documentation

Add a side-effect to a JavaScript handler

Description

With a JavaScript handler, once you have calculated a value based on the handler's arguments (e.g. name, value) you will likely want to produce a side-effect based on that calculated value. This function helps you do that.

Usage

vw_handler_add_effect(vw_handler, body_effect, ...)

Arguments

vw_handler

vw_handler created using vw_handler_signal() or vw_handler_event()

body_effect

character, the name of a defined handler-body, or the text of the body of a handler-function

...

additional named parameters to be interpolated into the text of the handler_body

Details

The calculation of a value is meant to be separate from the production of a side-effect. This way, the code for a side-effect can be used for any type of handler.

You are supplying the body_effect to an effect-handler. This takes a single argument, x, representing the calculated value. Doing this allows us to chain side-effects together; be careful not to modify x in any of the code you provide.

To see what side-effects are available in this package's handler-library, call vw_handler_add_effect() without any arguments. You may notice that some of the effects, like "element_text", require additional parameters, in this case, selector.

Those parameters with a default value of NULL require you to supply a value; those with sensible defaults are optional.

To provide the parameters, call vw_handler_add_effect() with named arguments corresponding to the names of the parameters. See the examples for details.

Value

modified copy of vw_handler

See Also

vw_handler_signal()

Examples

  # list all the available effect-handlers
  vw_handler_add_effect()

  # build a signal handler that prints some text,
  # then the value, to the console
  vw_handler_signal("value") %>%
    vw_handler_add_effect("console", label = "signal value:")


vegawidget documentation built on May 29, 2024, 12:17 p.m.