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.

The DomEvent.filter() of an event type is a JavaScript expression in an annotation too, and the client runs it like event data, so a filter that is not a property path is put into the bundle in the same way, see getBundledFilter(Class). A filter and event data with the same expression share one function.

For internal use only. May be renamed or removed in a future release.

Since:
25.4
  • 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 @Nullable String
    getBundledFilter(Class<?> eventType)
    Gets the DomEvent.filter() of the given event type if the build puts it into the bundle as a function, which is a filter that is not a property path.
    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 or filter, which is what the server sends instead of the expression.
    static boolean
    Checks whether the given DomEvent.filter() is put into the bundle as a function, which is a filter that is not empty and not a property path that the client reads without compiling it.
    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
    • getBundledFilter

      public static @Nullable String getBundledFilter(Class<?> eventType)
      Gets the DomEvent.filter() of the given event type if the build puts it into the bundle as a function, which is a filter that is not a property path. The event type is read like the build reads it, also when it inherits the annotation.
      Parameters:
      eventType - a component event type annotated with DomEvent, not null
      Returns:
      the filter, or null if the event type has no filter or the client reads it without compiling it
    • isBundledFilter

      public static boolean isBundledFilter(String filter)
      Checks whether the given DomEvent.filter() is put into the bundle as a function, which is a filter that is not empty and not a property path that the client reads without compiling it.
      Parameters:
      filter - the filter of a DomEvent annotation, not null
      Returns:
      true if the server sends the identifier of the function of the bundle for the filter
    • 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 or filter, 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, or a filter that getBundledFilter(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