Interface TriggerJs
- All Superinterfaces:
Serializable
The JavaScript that the built-in triggers and actions share, as snippets for
JsSnippets.of(Class): the actions that report to the server through a
return channel or write an element property, and the installers that hook an
action up to its trigger in the browser. What a single action does in the
browser is declared next to that action, and the inputs that produce a value
are in TriggerInputJs.
An action is a function that does its work, called with the event of the
trigger as event. An installer is applied to the host element of
the trigger and returns the function that uninstalls it, as an initializer of
Element.addJsInitializer(JsFunction) does. Functions are composed by
passing one snippet as an argument of another, which calls it.
For internal use only. May be renamed or removed in a future release.
-
Method Summary
Modifier and TypeMethodDescriptioncallChannel(ReturnChannelRegistration channel) An action that calls a return channel without a value.listenToEvent(JsFunction action, String eventName) An installer that runs an action whenever the element receives a DOM event with the given name.observeSize(JsFunction action) An installer that runs an action with the size of the element whenever it changes, as{width, height}.reportOutcome(JsFunction promise, ReturnChannelRegistration channel) An action that runs a promise-returning action and reports the outcome of the promise to a return channel, as{ok, value}when it resolves or as{ok, error: {name, message}}when it rejects.runAfterTimeout(JsFunction action, long delayMillis) An installer that runs an action once, after the given delay.sendToChannel(ReturnChannelRegistration channel, JsFunction source) An action that sends the value of an input to a return channel.setProperty(Element target, String propertyName, JsFunction source) An action that assigns the value of an input to a property of an element.
-
Method Details
-
callChannel
An action that calls a return channel without a value.- Parameters:
channel- the return channel to call- Returns:
- the action function
-
sendToChannel
@JsExpression("$0($1(event));") @JsFunctionParameterNames("event") JsFunction sendToChannel(ReturnChannelRegistration channel, JsFunction source) An action that sends the value of an input to a return channel.- Parameters:
channel- the return channel to callsource- the input that produces the value- Returns:
- the action function
-
setProperty
@JsExpression("$0[$1] = $2(event)") @JsFunctionParameterNames("event") JsFunction setProperty(Element target, String propertyName, JsFunction source) An action that assigns the value of an input to a property of an element.- Parameters:
target- the element to modifypropertyName- the name of the propertysource- the input that produces the value- Returns:
- the action function
-
reportOutcome
@JsExpression("$0(event).then(value => $1({ok: true, value: value})).catch(e => $1({ok: false, error: {name: (e && e.name) ? e.name : \'\',message: (e && e.message) ? e.message : String(e)}}));") @JsFunctionParameterNames("event") JsFunction reportOutcome(JsFunction promise, ReturnChannelRegistration channel) An action that runs a promise-returning action and reports the outcome of the promise to a return channel, as{ok, value}when it resolves or as{ok, error: {name, message}}when it rejects.- Parameters:
promise- the action that returns the promisechannel- the return channel to report the outcome to- Returns:
- the action function
-
listenToEvent
@JsExpression("this.addEventListener($1, $0);return () => this.removeEventListener($1, $0);") JsFunction listenToEvent(JsFunction action, String eventName) An installer that runs an action whenever the element receives a DOM event with the given name.- Parameters:
action- the action to run with the eventeventName- the name of the DOM event- Returns:
- the installer function
-
runAfterTimeout
@JsExpression("const id = setTimeout(() => $0(), $1);return () => clearTimeout(id);") JsFunction runAfterTimeout(JsFunction action, long delayMillis) An installer that runs an action once, after the given delay.- Parameters:
action- the action to rundelayMillis- the delay in milliseconds- Returns:
- the installer function
-
observeSize
@JsExpression("return window.Vaadin.Flow.elementResize.observe(this, $0);") JsFunction observeSize(JsFunction action) An installer that runs an action with the size of the element whenever it changes, as{width, height}.- Parameters:
action- the action to run with the size- Returns:
- the installer function
-