feat: JsFunction.withParameter and named captures for triggers#24465
Open
Artur- wants to merge 1 commit into
Open
feat: JsFunction.withParameter and named captures for triggers#24465Artur- wants to merge 1 commit into
Artur- wants to merge 1 commit into
Conversation
Adds a JsFunction.withParameter(name, value) primitive that prepends
`let <name>=$<N>;` and appends the value as a capture, so a function
body can reference values by name instead of by positional `$N`:
element.addJsInitializer(JsFunction.of("setup(target)")
.withParameter("target", someElement));
The new addJsInitializer(JsFunction) overload accepts pre-built
JsFunctions; the existing addJsInitializer(String, Object...) form
delegates to it, and ElementJsInitializerRegistration now takes the
JsFunction directly instead of rebuilding it from a string/array.
Sweeps the trigger/action/input toJs and toPromiseJs bodies to use the
new named form so each rendered fragment reads as its own JS:
DomEventTrigger addEventListener(eventName, action) / removeEventListener(...)
CallbackAction channel(source(event))
PromiseAction observer(inner(event), channel)
HandlerInput return event[propertyName]
PropertyInput return target[propertyName]
SetPropertyAction target[propertyName] = source(event)
SignalInput return target[propertyName]
RequestFullscreenAction return target.requestFullscreen()
WriteToClipboardAction writePayload(text(event), html(event))
The companion "// \$N = ..." comments are gone — the names in the body
now match the captures. Trigger.install's Javadoc example uses the
same form so subclasses are pointed at the named API.
Duplicate parameter names, and names that collide with a previously
declared withArguments name, are rejected.
|
Member
|
I'm not sure this is a good idea after all. See |
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.



Adds a JsFunction.withParameter(name, value) primitive that prepends
let <name>=$<N>;and appends the value as a capture, so a function body can reference values by name instead of by positional$N:The new addJsInitializer(JsFunction) overload accepts pre-built JsFunctions; the existing addJsInitializer(String, Object...) form delegates to it, and ElementJsInitializerRegistration now takes the JsFunction directly instead of rebuilding it from a string/array.
Sweeps the trigger/action/input toJs and toPromiseJs bodies to use the new named form so each rendered fragment reads as its own JS:
DomEventTrigger addEventListener(eventName, action) / removeEventListener(...)
CallbackAction channel(source(event))
PromiseAction observer(inner(event), channel)
HandlerInput return event[propertyName]
PropertyInput return target[propertyName]
SetPropertyAction target[propertyName] = source(event)
SignalInput return target[propertyName]
RequestFullscreenAction return target.requestFullscreen()
WriteToClipboardAction writePayload(text(event), html(event))
The companion "// $N = ..." comments are gone — the names in the body now match the captures. Trigger.install's Javadoc example uses the same form so subclasses are pointed at the named API.
Duplicate parameter names, and names that collide with a previously declared withArguments name, are rejected.