Class ReactiveEventRouter<L,E extends ReactiveValueChangeEvent>

java.lang.Object
com.vaadin.client.flow.reactive.ReactiveEventRouter<L,E>
Type Parameters:
L - the listener type of this router
E - the reactive event type of this router

public abstract class ReactiveEventRouter<L,E extends ReactiveValueChangeEvent> extends Object
Event router providing integration with reactive features in Reactive and Computation. Listeners can be added both for a specific event type and for the generic value change. All events are fired to both types of listeners, as well as to event collectors registered using Reactive.addEventCollector(ReactiveValueChangeListener).
Since:
1.0
Author:
Vaadin Ltd
  • Constructor Details

    • ReactiveEventRouter

      public ReactiveEventRouter(ReactiveValue reactiveValue)
      Creates a new event router for a reactive value.
      Parameters:
      reactiveValue - the reactive value, not null
  • Method Details

    • addListener

      public elemental.events.EventRemover addListener(L listener)
      Adds a listener to this event router.
      Parameters:
      listener - the listener to add, not null
      Returns:
      an event remover that can be used for removing the added listener
    • addReactiveListener

      public elemental.events.EventRemover addReactiveListener(ReactiveValueChangeListener reactiveValueChangeListener)
      Adds a generic reactive change listener to this router.
      Parameters:
      reactiveValueChangeListener - the change listener to add, not null
      Returns:
      an event remover that can be used for removing the added listener
    • fireEvent

      public void fireEvent(E event)
      Fires an event to all listeners added to this router using addListener(Object) or addReactiveListener(ReactiveValueChangeListener) as well as all global event collectors added using Reactive.addEventCollector(ReactiveValueChangeListener).
      Parameters:
      event - the event to fire
    • registerRead

      public void registerRead()
      Registers access to the data for which this event router fires event. This registers the event source of this event router to be set as a dependency of the current computation if there is one.
    • getReactiveValue

      public ReactiveValue getReactiveValue()
      Gets the reactive value for which this router fires event.
      Returns:
      the reactive value
    • wrap

      protected abstract L wrap(ReactiveValueChangeListener reactiveValueChangeListener)
      Callback for wrapping a generic reactive change listener to an instance of the listener type natively supported by this event router.
      Parameters:
      reactiveValueChangeListener - the reactive change listener
      Returns:
      an event listener wrapping the provided listener
    • dispatchEvent

      protected abstract void dispatchEvent(L listener, E event)
      Callback for dispatching an event to a listener.
      Parameters:
      listener - the listener that should receive the event
      event - the event to dispatch