Fix #770: unwrap var-from-def before applying the viewer#811
Open
borkdude wants to merge 5 commits into
Open
Conversation
When a `def` has an explicit viewer like `^{::clerk/viewer clerk/row}`,
the viewer should see the def's value, not the internal
`{:var-from-def ... :var-snapshot ...}` map Clerk adds around it.
Before, that map was passed to function viewers, which either crashed
(#770) or rendered the raw map. Now the value is unwrapped first,
unless the viewer opts out with `:var-from-def? true` (as
`render-eval-viewer` does).
Function viewers whose returned viewer map opts out of var-from-def unwrapping need to advertise that intent upfront, otherwise the outer code can't know whether to pass the raw var-from-def map or the deref'd value. Metadata on the fn value lets `apply-viewer- unwrapping-var-from-def` decide in a single pass. Also updates the viewer-test case for fn viewers to use meta-based opt-out instead of the post-hoc return-shape detection.
Fn viewers that opted out via `(assoc returned-viewer :var-from-def? true)` keep working: on the unwrap path the fn is called once with the deref'd value, the result's `:var-from-def?` is checked, and on opt-out the fn is called again with the raw var-from-def wrapper. Slider/text-input don't need meta tags anymore (reverted experimental.clj). New behavior for `clerk/row`/`col` on defs: single call with the deref'd value, 3-cell row output. Legacy fn viewers still opt out as before, at the cost of one extra fn call on that path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a
defhas an explicit viewer like^{::clerk/viewer clerk/row}, the viewer should see the def's value, not the internal{:var-from-def ... :var-snapshot ...}map Clerk adds around it. Before, that map was passed to function viewers, which either crashed (#770) or rendered the raw map. Now the value is unwrapped first, unless the viewer opts out with:var-from-def? true(asrender-eval-viewerdoes).