EventProcessor

com.raquo.laminar.keys.EventProcessor
See theEventProcessor companion object
class EventProcessor[Ev <: Event, V](val eventProp: EventProp[Ev], val shouldUseCapture: Boolean, val shouldBePassive: Boolean, val processor: Ev => Option[V])

This class represents a sequence of transformations that are applied to events feeding into an EventListener EventProcessor-s are immutable, so can be reused by multiple setters.

Example syntax: input(onChange().preventDefault.mapTo(true) --> myBooleanWriteBus)

Note: Params are protected to avoid confusing autocomplete options (e.g. "useCapture")

Value parameters

processor

Processes incoming events before they're passed to the next processor or to the listening EventBus. Returns an Option of the processed value. If None, the value should not passed down the chain.

shouldUseCapture

(false means using bubble mode) See useCapture docs here: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def -->(sink: Sink[V]): EventListener[Ev, V]
def -->(onNext: V => Unit): EventListener[Ev, V]
def -->(onNext: => Unit)(implicit evidence: UnitArrowsFeature): EventListener[Ev, V]
def collect[V2](pf: PartialFunction[V, V2]): EventProcessor[Ev, V2]
def compose[Out](operator: EventStream[V] => Observable[Out]): LockedEventKey[Ev, V, Out]

Similar to the Airstream compose operator.

Similar to the Airstream compose operator.

Use this when you need to apply stream operators on this element's events, e.g.:

div(onScroll.compose(_.throttle(100)) --> observer)

a(onClick.preventDefault.compose(_.delay(100)) --> observer)

Note: This method is not chainable. Put all the operations you need inside the operator callback.

Attributes

def filter(passes: V => Boolean): EventProcessor[Ev, V]

Values that do not pass will not propagate down the chain and into the emitter.

Values that do not pass will not propagate down the chain and into the emitter.

Attributes

def flatMap[Out, Obs <: (Observable)](operator: V => Obs[Out])(implicit flattenStrategy: FlattenStrategy[EventStream, Obs, Observable]): LockedEventKey[Ev, V, Out]

Similar to the Airstream flatMap operator.

Similar to the Airstream flatMap operator.

Use this when you want to create a new stream or signal on every event, e.g.:

button(onClick.preventDefault.flatMap(_ => makeAjaxRequest()) --> observer)

#TODO[IDE] IntelliJ (2022.3.2) shows false errors when using this flatMap implementation, at least with Scala 2, making it annoying. Use flatMapStream or flatMapSignal to get around that.

Note: This method is not chainable. Put all the operations you need inside the operator callback, or use the compose method instead for more flexibility

Attributes

def flatMapSignal[Out](operator: V => Signal[Out])(implicit flattenStrategy: FlattenStrategy[EventStream, Signal, Observable]): LockedEventKey[Ev, V, Out]

Similar to flatMap, but restricted to signals only.

Similar to flatMap, but restricted to signals only.

Attributes

def flatMapStream[Out](operator: V => EventStream[Out])(implicit flattenStrategy: FlattenStrategy[EventStream, EventStream, Observable]): LockedEventKey[Ev, V, Out]

Similar to flatMap, but restricted to streams only.

Similar to flatMap, but restricted to streams only.

Attributes

def map[V2](project: V => V2): EventProcessor[Ev, V2]
def mapRaw[V2](project: (Ev, Option[V]) => Option[V2]): EventProcessor[Ev, V2]

(originalEvent, accumulatedValue) => newAccumulatedValue

(originalEvent, accumulatedValue) => newAccumulatedValue

Unlike other processors, this one will fire regardless of .filter-s up the chain. Instead, if the event was filtered, project will receive None as accumulatedValue. The output of project should be Some(newValue), or None if you want to filter out this event.

Attributes

def mapTo[V2](value: => V2): EventProcessor[Ev, V2]

Same as map(_ => value)

Same as map(_ => value)

Note: value will be re-evaluated every time the event is fired

Attributes

def mapToChecked: EventProcessor[Ev, Boolean]

Get the value of event.target.checked

Get the value of event.target.checked

Attributes

def mapToEvent: EventProcessor[Ev, Ev]

Get the original event. You might want to call this in a chain, after some other processing.

Get the original event. You might want to call this in a chain, after some other processing.

Attributes

def mapToFiles: EventProcessor[Ev, List[File]]

Get the value of event.target.files

def mapToStrict[V2](value: V2): EventProcessor[Ev, V2]

Like mapTo, but with strict evaluation of the value

Like mapTo, but with strict evaluation of the value

Attributes

def mapToTargetAs[Ref <: EventTarget]: EventProcessor[Ev, Ref]

Unsafe – Get the value of event.target, cast to a certain element type

Unsafe – Get the value of event.target, cast to a certain element type

You should generally avoid this in favor of other helpers like mapToValue or inContext { thisNode => ... }.

Attributes

def mapToUnit: EventProcessor[Ev, Unit]
def mapToValue: EventProcessor[Ev, String]

Get the value of event.target.value

Get the value of event.target.value

Attributes

Use a standard non-passive listener. You don't need to call this unless you set passive previously, and want to revert to non-passive.

Use a standard non-passive listener. You don't need to call this unless you set passive previously, and want to revert to non-passive.

See passive docs here: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#passive

Attributes

def orElseEval(f: Ev => Unit): EventProcessor[Ev, V]

Evaluate f if the value was filtered out up the chain. For example:

Evaluate f if the value was filtered out up the chain. For example:

onClick.filter(isRightClick).orElseEval(_.preventDefault()) --> observer

This observer will fire only on right clicks, and for events that aren't right clicks, ev.preventDefault() will be called instead.

Attributes

def passive: EventProcessor[Ev, V]

Use a passive event listener

Use a passive event listener

Note that unlike preventDefault config which applies to individual events, passive is used to install the listener onto the DOM node in the first place.

See passive docs here: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#passive

Attributes

Prevent default browser action for the given event (e.g. following the link when it is clicked) https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault

Prevent default browser action for the given event (e.g. following the link when it is clicked) https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault

Note: this is just a standard processor, so it will be fired in whatever order you have applied it. So for example, you can filter events before applying this, preventing default action only for certain events.

Example: input(onKeyUp().filter(ev => ev.keyCode == KeyCode.Tab).preventDefault --> tabKeyUpBus)

Attributes

def setAsChecked(implicit boolEvidence: V <:< Boolean): EventProcessor[Ev, V]

Write the resulting boolean into event.target.checked. You can only do this on checkbox or radio button elements.

Write the resulting boolean into event.target.checked. You can only do this on checkbox or radio button elements.

Warning: if using this, do not use preventDefault. The browser may override the value you set here.

Attributes

def setAsValue(implicit stringEvidence: V <:< String): EventProcessor[Ev, V]

Write the resulting string into event.target.value. You can only do this on elements that have a value property - input, textarea, select

Write the resulting string into event.target.value. You can only do this on elements that have a value property - input, textarea, select

Attributes

def setChecked(nextChecked: Boolean): EventProcessor[Ev, V]

Write a custom boolean into event.target.checked. You can only do this on checkbox or radio button elements.

Write a custom boolean into event.target.checked. You can only do this on checkbox or radio button elements.

Warning: if using this, do not use preventDefault. The browser may override the value you set here.

Attributes

def setValue(nextValue: String): EventProcessor[Ev, V]

Write a custom string into event.target.value. You can only do this on elements that have a value property - input, textarea, select

Write a custom string into event.target.value. You can only do this on elements that have a value property - input, textarea, select

Attributes

This method prevents other listeners of the same event from being called. If several listeners are attached to the same element for the same event type, they are called in the order in which they were added. If stopImmediatePropagation() is invoked during one such call, no remaining listeners will be called.

This method prevents other listeners of the same event from being called. If several listeners are attached to the same element for the same event type, they are called in the order in which they were added. If stopImmediatePropagation() is invoked during one such call, no remaining listeners will be called.

MDN https://developer.mozilla.org/en-US/docs/Web/API/Event/stopImmediatePropagation

Note: this is just a standard processor, so it will be fired in whatever order you have applied it. So for example, you can filter events before applying this, propagation will be stopped only for certain events.

Example: div(onClick.filter(isGoodClick).stopImmediatePropagation --> goodClickBus)

Attributes

Propagation here refers to DOM Event bubbling or capture propagation. https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation

Propagation here refers to DOM Event bubbling or capture propagation. https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation

Note: this is just a standard processor, so it will be fired in whatever order you have applied it. So for example, you can filter events before applying this, propagation will be stopped only for certain events.

Example: div(onClick.filter(isGoodClick).stopPropagation --> goodClickBus)

Attributes

Use standard bubble propagation mode. You don't need to call this unless you set useCapture previously, and want to revert to bubbling.

Use standard bubble propagation mode. You don't need to call this unless you set useCapture previously, and want to revert to bubbling.

See useCapture docs here: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#usecapture

Attributes

Use capture mode

Use capture mode

Note that unlike preventDefault config which applies to individual events, useCapture is used to install the listener onto the DOM node in the first place.

See useCapture docs here: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#usecapture

Attributes