Class BundledEventData

java.lang.Object
com.vaadin.flow.component.internal.BundledEventData

public final class BundledEventData extends Object
Tells which 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 Type
    Method
    Description
    static List<String>
    getBundledEventData(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 String
    getExpression(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 String
    getFunctionId(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 boolean
    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.
    static List<String>
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getBundledEventData

      public static List<String> getBundledEventData(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.

      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 with DomEvent, not null
      Returns:
      an unmodifiable list of the EventData values 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

      public static List<String> 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.
      Parameters:
      eventType - a component event type annotated with DomEvent, not null
      listenerEventData - the event data of the event type, as ComponentEventBusUtil.getListenerEventData(Class) returns it, not null
      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

      public static String getFunctionId(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. 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 that getBundledEventData(Class) returns, not null
      Returns:
      the identifier of the function, not null
    • getExpression

      public static String getExpression(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.
      Parameters:
      eventData - event data that getBundledEventData(Class) returns, not null
      Returns:
      the expression, not null
    • isMappedToElement

      public static boolean isMappedToElement(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.
      Parameters:
      eventData - event data that getBundledEventData(Class) returns, not null
      Returns:
      true if the value is mapped to a component or an element