Repository navigation
References: list every package function by section, and teach a widget by its protocol - #7006
Conversation
…tocol The module references taught `LeafElement`'s `setup`, `render`, `record`, `takeBack` and `defer` in three files, though the class is a library module whose header is its contract. They now teach a widget by the protocol alone (properties in, events out) and give the class one section that says what it is, when a widget needs it, and where its contract is. module-authoring.md opens with the protocol in a paragraph and a list of every export of widget-api.js under the section that describes it. tests/runtime/widget-api.test.mjs holds the list to the exports and each entry to its section, in place of the check that every export is named somewhere. Also: the arguments and members the references left out (`says`, `readObligations`, `rowWalk`, `tabStore`, `restorePlace`, `shownWindow`, `pushEntry` and `replaceEntry`), exact library modules where a pointer named only the library, and the sentences six fresh authors were stuck on.
…der binds handlers
leaf-agent
left a comment
There was a problem hiding this comment.
The references now give an author two rules for when a widget extends LeafElement, and the rules disagree. module-authoring.md, "The interface", and the first sentence of module-plain-elements.md, "LeafElement", say a widget that draws with Lit extends the class. But module-plain-elements.md opens with a widget that draws with Lit on a bare HTMLElement, and the last paragraph of that section bases the choice on page readings: "Only the class follows a page reading, so a widget that draws from one extends it." An author who copies the opening example breaks the rule the index states, and an author who follows the index can't tell why the example is allowed.
The two suggestions below keep the push toward the class and make the page-reading rule the required one, so the opening example becomes an allowed case instead of a counterexample. If the intent is that every Lit widget extends the class, the other fix is to say that the opening example shows the bare protocol, not the recommended form.
The index in module-authoring.md, which tests/runtime/widget-api.test.mjs holds to the exports since #7006, still named matchesWhen, partOver and consumeAnnotations.
An author new to Leaf now finds every function
widget-api.jsexports from one list, and learns a widget as the redesign made it: a custom element Leaf drives by properties and events. This is the references step of the package-interface redesign, scoped by its aim rather than by its old target of one 4,000-word file.What changed
module-authoring.mdopens with the protocol in a paragraph, then lists every export under the section that describes it.tests/runtime/widget-api.test.mjsholds that list to the exports and each entry to its section. It replaces the check that every export is named somewhere in the nine files.LeafElementtaught once. Three files taught the class'ssetup,render,record,takeBackanddefer, which its header in the library also documents. The references now speak in the protocol's terms, and one section ofmodule-plain-elements.mdsays what the class is, when a widget extends it, where it draws, and that its header is its contract.says(drawn,until),readObligations(byId),rowWalk(position,steps),tabStore(read,keys,where),restorePlace(intent),shownWindow(viewport), andpushEntryandreplaceEntry(state).$keys; an authored starting value answers anawaits; an event's promise is itscompleteproperty.The nine
module-*.mdfiles hold 25,419 words, against 25,424 before. The index, the left-out arguments and the class's one section went in; the class's teaching inmodule-authoring.mdandmodule-state.mdand two lists that repeated the protocol came out.Measurement
Before and after, six agents on Sonnet that had never seen Leaf's code each built one package from the shipped skill alone, barred from
browser/,src/,packages/andtests/. A second agent then used each widget in a headless browser, since the render check draws a page and presses nothing.package checkandpage checkwith--renderThe first revision cut the class to a pointer at its header. Every author then wrote a plain
HTMLElement, and one widget passed both checks with dead handlers, since Lit's standalonerenderdoesn't bind an@eventhandler to the element. The text now says when a widget extends the class and how a standalonerenderbinds handlers. The two tasks whose result had changed ran again on that text, and the After column counts those two reruns with the other four from the first revision.Both source reads were of the library's
rank.js, forrankAt's arguments. A ranked list can't record a move without that function, and the references name library modules without describing their functions.Leaf's own suite, base beside head on Claude Code:
widget-controller-lifetime6 of 8 and 8 of 8,widget-list-keeps-focus4 of 5 and 5 of 5,thread-widget-actions1 of 3 and 3 of 3. An earlier head scored 1 of 5 on the first of these until two sentences came back: aLeafElementreads a bound property inrender(), and places retained nodes there.widget-list-keeps-focus's criterion now also passes a list drawn by thestatesetter that Leaf calls before thelf-actiondispatch returns.shared-contribution-actionsfails on both arms, 0 of 3 each.