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
Value members
Concrete methods
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.
(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.
Same as map(_ => value)
Same as map(_ => value)
Note: value
will be re-evaluated every time the event is fired
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.
Like mapTo, but with strict evaluation of the value
Like mapTo, but with strict evaluation of the value
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)
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.
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