Observer

trait Observer[-A] extends Sink[A] with Named
Companion:
object
trait Named
trait Sink[A]
class Object
trait Matchable
class Any
class WriteBus[A]

Value members

Abstract methods

def onError(err: Throwable): Unit

Note: must not throw!

Note: must not throw!

def onNext(nextValue: A): Unit

Note: must not throw!

Note: must not throw!

def onTry(nextValue: Try[A]): Unit

Note: must not throw!

Note: must not throw!

Concrete methods

def contracollect[B](pf: PartialFunction[B, A]): Observer[B]

Like contramap but with collect semantics: not calling the original observer when pf is not defined

Like contramap but with collect semantics: not calling the original observer when pf is not defined

Value parameters:
pf

Note: guarded against exceptions

def contracollectOpt[B](project: B => Option[A]): Observer[B]

Like contramap, but original observer only fires if project returns Some(value)

Like contramap, but original observer only fires if project returns Some(value)

So, similar to contracollect but optimized for APIs like NonEmptyList.fromList that return an Option.

Value parameters:
project

Note: guarded against exceptions

def contramap[B](project: B => A): Observer[B]

Creates another Observer such that calling its onNext will call this observer's onNext with the value processed by the project function.

Creates another Observer such that calling its onNext will call this observer's onNext with the value processed by the project function.

This is useful when you need to pass down an Observer[A] to a child component which should not know anything about the type A, but both child and parent know about type B, and the parent knows how to translate B into A.

Value parameters:
project

Note: guarded against exceptions

def contramapSome[V](implicit evidence: Option[V] <:< A): Observer[V]

Available only on Observers of Option, this is a shortcut for contramapB

Available only on Observers of Option, this is a shortcut for contramapB

def contramapTry[B](project: Try[B] => Try[A]): Observer[B]
Value parameters:
project

must not throw!

def debugBreak(when: Try[A] => Boolean): Observer[A]
Implicitly added by toDebuggableObserver

Trigger JS debugger for emitted events and errors if when passes

Trigger JS debugger for emitted events and errors if when passes

def debugBreakErrors(when: Throwable => Boolean): Observer[A]
Implicitly added by toDebuggableObserver

Trigger JS debugger for emitted errors (but not events) if when passes

Trigger JS debugger for emitted errors (but not events) if when passes

def debugBreakEvents(when: A => Boolean): Observer[A]
Implicitly added by toDebuggableObserver

Trigger JS debugger for emitted events (but not errors) if when passes

Trigger JS debugger for emitted events (but not errors) if when passes

def debugLog(when: Try[A] => Boolean, useJsLogger: Boolean): Observer[A]
Implicitly added by toDebuggableObserver

Log emitted events and errors if when condition passes, using dom.console.log if useJsLogger is true.

Log emitted events and errors if when condition passes, using dom.console.log if useJsLogger is true.

def debugLogErrors(when: Throwable => Boolean): Observer[A]
Implicitly added by toDebuggableObserver

Log emitted errors (but not regular events) if when condition passes

Log emitted errors (but not regular events) if when condition passes

def debugLogEvents(when: A => Boolean, useJsLogger: Boolean): Observer[A]
Implicitly added by toDebuggableObserver

Log emitted events (but not errors) if when condition passes, using dom.console.log if useJsLogger is true.

Log emitted events (but not errors) if when condition passes, using dom.console.log if useJsLogger is true.

def debugSpy(fn: Try[A] => Unit): Observer[A]
Implicitly added by toDebuggableObserver

Execute fn on every emitted event or error

Execute fn on every emitted event or error

def debugSpyErrors(fn: Throwable => Unit): Observer[A]
Implicitly added by toDebuggableObserver

Execute fn on every emitted error (but not regular events)

Execute fn on every emitted error (but not regular events)

def debugSpyEvents(fn: A => Unit): Observer[A]
Implicitly added by toDebuggableObserver

Execute fn on every emitted event (but not error)

Execute fn on every emitted event (but not error)

def debugWithName(displayName: String): Observer[A]
Implicitly added by toDebuggableObserver

Create a new observer with a displayName, that sends all events to the original observer. This is different from setDisplayName.

Create a new observer with a displayName, that sends all events to the original observer. This is different from setDisplayName.

If you say observer.debugWithName("foo").debugLog(), the displayName used by the logging observer will be "foo" verbatim, whereas if you say observer.setDisplayName("foo").debugLog(), the logger's displayName will be "foo|Debug" – with a suffix – to differentiate it from the "foo" displayName of observer itself.

def delay(ms: Int): Observer[A]

Creates another Observer such that calling it calls the original observer after the specified delay.

Creates another Observer such that calling it calls the original observer after the specified delay.

Note: unlike Observable operators, Observer operators are not ownership-aware, so this can fire the observer even after the subscription that bound this observer to the observable has been killed. So in Laminar for example, it's possible for such a delayed observer to fire even after the element that owns this subscription was unmounted. Use the Observable delay operator to avoid that.

Of course, whether anything happens if the observer is fired is a separate issue altogether. For example, if the observer is an EventBus writer, firing into it won't do anything if the EventBus stream is stopped.

def filter[B <: A](passes: B => Boolean): Observer[B]

Creates another Observer such that calling its onNext will call this observer's onNext with the same value, but only if it passes the test.

Creates another Observer such that calling its onNext will call this observer's onNext with the same value, but only if it passes the test.

Value parameters:
passes

Note: guarded against exceptions

override def toObserver: Observer[A]
Definition Classes

Inherited methods

protected def defaultDisplayName: String

This is the method that subclasses override to preserve the user's ability to set custom display names.

This is the method that subclasses override to preserve the user's ability to set custom display names.

Inherited from:
Named
final def displayName: String
Inherited from:
Named
def setDisplayName(name: String): Named.this.type

Set the display name for this instance (observable or observer).

Set the display name for this instance (observable or observer).

  • This method modifies the instance and returns this. It does not create a new instance.
  • New name you set will override the previous name, if any. This might change in the future. For the sake of sanity, don't call this more than once for the same instance.
  • If display name is set, toString will output it instead of the standard type@hashcode string
Inherited from:
Named
final override def toString: String

Override defaultDisplayName instead of this, if you need to.

Override defaultDisplayName instead of this, if you need to.

Definition Classes
Named -> Any
Inherited from:
Named

Concrete fields

Implicitly added by toDebuggableObserver
lazy val toJsFn1: Function1[A, Unit]