Class BundledEventData
EventData values of a DomEvent class the build
puts into the bundle as functions, and the identifier the server sends for
each of them instead of its JavaScript.
An EventData value is a JavaScript expression in an annotation, so it
is known when the application is built. The values that the client would
otherwise compile from a string, which a content security policy without
unsafe-eval does not allow, are generated into the bundle as
(event, element) => (value), keyed by a hash of the value.
The build and the server both decide through this class which values those
are and what their identifiers are, so they always agree.
A value that maps to a component or an element is in the event data with the
prefix JsonConstants.MAP_STATE_NODE_EVENT_DATA. Its function is the
expression without the prefix, so it shares the function of the same
expression used as a plain value, and the server tells the client with
JsonConstants.EVENT_SETTINGS_MAP_ELEMENT to map what the function
returns.
The values of a PrebuiltEventData event, which are keys rather than
JavaScript, are not put into the bundle. Neither is a value that the client
reads without compiling it, such as a property path like
event.clientX.
For internal use only. May be renamed or removed in a future release.
-
Method Summary
Modifier and TypeMethodDescriptiongetBundledEventData(Class<? extends ComponentEvent<?>> eventType) Gets the event data of the given event type that the build puts into the bundle as functions, in constructor parameter order.static StringgetExpression(String eventData) Gets the JavaScript expression of the given bundled event data, which is what the function of the bundle returns: the event data without the prefix of a value mapped to a component or an element.static StringgetFunctionId(String eventData) Gets the identifier of the function that the bundle registers for the given bundled event data, which is what the server sends instead of the expression.static booleanisMappedToElement(String eventData) Checks whether the client maps what the expression of the given event data returns to the closest state node, which is how a value of a component or an element parameter is sent.selectBundled(Class<?> eventType, List<String> listenerEventData) Selects the event data that the build puts into the bundle as functions from the event data of the given event type.
-
Method Details
-
getBundledEventData
Gets the event data of the given event type that the build puts into the bundle as functions, in constructor parameter order.For the build, which loads the event type with a class loader it closes afterwards: the event type is scanned without a cache, as a static map would otherwise keep that class loader alive.
- Parameters:
eventType- a component event type annotated withDomEvent, notnull- Returns:
- an unmodifiable list of the
EventDatavalues that are sent as the identifier of a function of the bundle, empty if there are none - Throws:
IllegalArgumentException- if the event type has no suitable DOM event constructor
-
selectBundled
Selects the event data that the build puts into the bundle as functions from the event data of the given event type.- Parameters:
eventType- a component event type annotated withDomEvent, notnulllistenerEventData- the event data of the event type, asComponentEventBusUtil.getListenerEventData(Class)returns it, notnull- Returns:
- an unmodifiable list of the values of the given event data that are sent as the identifier of a function of the bundle, in the same order, empty if there are none
-
getFunctionId
Gets the identifier of the function that the bundle registers for the given bundled event data, which is what the server sends instead of the expression. A hash of the expression, so that nothing in the browser names the class that declared it. A value mapped to a component or an element has the identifier of its expression without the prefix.- Parameters:
eventData- event data thatgetBundledEventData(Class)returns, notnull- Returns:
- the identifier of the function, not
null
-
getExpression
Gets the JavaScript expression of the given bundled event data, which is what the function of the bundle returns: the event data without the prefix of a value mapped to a component or an element.- Parameters:
eventData- event data thatgetBundledEventData(Class)returns, notnull- Returns:
- the expression, not
null
-
isMappedToElement
Checks whether the client maps what the expression of the given event data returns to the closest state node, which is how a value of a component or an element parameter is sent.- Parameters:
eventData- event data thatgetBundledEventData(Class)returns, notnull- Returns:
trueif the value is mapped to a component or an element
-