feat(session): Add $removeInputs()
method
#4293
Open
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.
For #2374
This is a bit of proof-of-concept, but isn't far from something we could ship. The idea is to add a
$remove()
method toReactiveValues
and asession$removeInputs()
that uses this method to remove a key from a reactive values list. Some notes:Removing an input only removes it from the list of inputs, without invalidating its value. This means that downstream observers that use this value directly aren't updated unless by another method. This preserves the current behavior, but if a future update is performed (because another reactive value is invalidated), reading the removed input has the same behavior as reading an un-initialized input.
On the other hand, we do invalidate
names(input)
andreactiveValuesToList(input)
, since these have effectively changed due to the removal of the input.session$removeInputs()
removes the input from the map on the server side. It does not change behavior on the client. We may need to revisit this and potentially remove any bindings to the input ID. I think this might be a good idea to ensure that if you add a new input UI with the same ID as a previous, but server-side removed input, it will be treated as a brand-new input. An alternative would be to make sure that UI added viainsertUI()
andrenderUI()
always report input values when bound (as opposed to only reporting changed values if the initial value is different from the last value before it was removed).Here's a small app that shows all of the above behavior: