registerInputHandler support, redux #28
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a second attempt at adding support for
shiny::registerInputHandler()
. In my first attempt, I didn't understand the purpose ofgetType()
. Now, I understand that an input's type is a namespace distinct from the name argument ofShiny.inputBindings.register()
and with a different extent. Using an input's name as its type, as I did in #26, made no sense.An input's name is used to alter the priority of an input in the event of a DOM conflict, and there is a 1-1 correspondence between an input and its name.
An input's type, on the other hand, has a different purpose. In R,
shiny::registerInputHandler()
is used to associate a type with an input handler that will coerce an input's value with a a matching type from a JSON representation to some alternate R representation.So, every input has one and only one name, and also (optionally) a type, but multiple inputs may share a type.
To implement this, I added a new property to the
options
argument ofreactR.reactShinyInput()
:type
.type
may be a function, used as the input'sgetType()
implementation. For expedience,type
may also befalse
or a type name string, which is probably the most common use case.I updated https://github.com/react-R/colorpicker-example to demonstrate usage of the functionality in this PR.