EventProcessor

class EventProcessor[Ev <: Event, V](val eventProp: ReactiveEventProp[Ev], val shouldUseCapture: 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

Companion:
object
class Object
trait Matchable
class Any

Value members

Concrete methods

def -->(sink: Sink[V]): EventListener[Ev, V]
def -->[El <: Base](onNext: V => Unit): EventListener[Ev, V]
def collect[V2](pf: PartialFunction[V, V2]): EventProcessor[Ev, V2]
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.

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.

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

def mapToChecked: EventProcessor[Ev, Boolean]

Get the value of event.target.checked

Get the value of event.target.checked

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.

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

def mapToValue: EventProcessor[Ev, String]

Get the value of event.target.value

Get the value of event.target.value

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.

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)

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.

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

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)

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)

Use standard bubble propagation mode. You don't need to call this unless you set useCapture previously.

Use standard bubble propagation mode. You don't need to call this unless you set useCapture previously.

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

Use capture mode (v=true) or bubble mode (v=false)

Use capture mode (v=true) or bubble mode (v=false)

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