Skip to content

Fix #770: unwrap var-from-def before applying the viewer#811

Open
borkdude wants to merge 5 commits into
mainfrom
issue-770-deref-first
Open

Fix #770: unwrap var-from-def before applying the viewer#811
borkdude wants to merge 5 commits into
mainfrom
issue-770-deref-first

Conversation

@borkdude
Copy link
Copy Markdown
Collaborator

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).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant