Repository navigation
Write a value in JSX as itself, kept current by Solid - #11
Merged
Merged
Conversation
A value that changes was given in JSX as a thunk the caller wrote,
title=(fun () -> S.get note), where TSX writes title={note()}: the most
written form in every component was the one furthest from Solid's, and
fun () -> meant a thunk there, so a callback that takes nothing had to
be written fun _ ->. 0.10.0 also took ?title=note for an accessor of an
option, while title=note was a value, two meanings for one form.
The ppx now reads a value as Solid's compiler reads TSX: a literal, a
name, an element and a function are given as they are, and any other
expression is a thunk the ppx writes, read again as what it reads
changes. A function is a function wherever it is given, so a thunk
written in JSX is refused by its type, and there is one form for each
meaning, required or optional, attribute or child. Outside JSX a thunk
is still written, fun () -> e, as TSX writes () => e.
Keeping the caller's thunk was weighed: it shows where a read is
deferred, but every read pays for it, and Solid's own users already
expect JSX to defer. Lowering is unchanged, so Solid's compiler sees
the same JSX it did.
A child given by its name, or a function's result given as one, met two types for one meaning: Jsx.element and Jsx.content, which Solid does not tell apart, and a conversion between them that inference could not always place. What JSX holds is now one type, Jsx.element, as Solid's JSX.Element is. An accessor was its representation, so an error printed Melange's (unit -> string [@U]); it is now an abstract type, named in the error. A function child is typed after the props it reads, a function written as a value is refused at the child with the kinds the component takes, and a Switch case that is not JSX is a child as it is.
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.
Why
A value that changes was given in JSX as a thunk the caller wrote,
title=(fun () -> S.get note), and a name could mean a value or, given to an optional prop, an accessor: the same value had more than one form, andfun () ->meant a thunk in JSX, so a callback that takes nothing was writtenfun _ ->. What JSX holds was two types,Jsx.elementandJsx.content, which Solid does not tell apart, and an accessor was its representation, so an error printed Melange's(unit -> string [@u]).A value in JSX is now written as itself and Solid keeps it current: a literal or a name is given as it is, any other expression is read again as what it reads changes, as Solid's compiler makes an expression in JSX a getter, and a function is a function. Evaluation follows JSX's form, as the body of
let%mapfollows its own in OCaml's reactive libraries; outside JSX a thunk is still written,fun () -> e, as Solid's own API takes() => e. Keeping the caller's thunk was weighed: it shows the deferral where it is written, but it gives a constant two forms, by name or computed, which no syntactic ppx can unify.Changes
title=(fun () -> S.get note)istitle=(S.get note), a child(fun () -> Jsx.int (S.get count))is(Jsx.int (S.get count)),?hidden=(Jsx.attr (fun () -> o))is?hidden=(Jsx.attr o).?title=note, which 0.10.0 took for an accessor of an option, is an option given as it is; a signal or a prop is?title=(S.get note).Jsx.element, as Solid'sJSX.Elementis;Jsx.contentisJsx.element, andJsx.element xandJsx.of_content xarex. A child given by its name takes an element,let icon = <Icon /> in <button>icon "Save"</button>.Solid.accessoris abstract, so an error names it,string Solidtype.Solid.accessor; an accessor is made byS.accessor (fun () -> e).Check.nodesisCheck.elements, and the children kind`nodesis`elements.(fun () -> ...).Switchtakes amatchas its child, with no thunk around it, its cases JSX or not.<Show.Some some=(S.get item)>(fun i -> ...)</Show.Some>takesi's type fromsome.Verified
make test: dune's tests, the plugin's and vitest's 965, hydration and Astro's prerender among them;make lint, every generator's--checkamong it;make docswith no warning.test/does_not_compile.tlists each position -- attribute, optional prop, component prop,data_, namespaced,as_, child,Switchcase, function child -- with every form that compiles and a thunk refused in each; no error in it shows[@u]or a name of the ppx's.