BaseObservable

com.raquo.airstream.core.BaseObservable
See theBaseObservable companion object
trait BaseObservable[+Self <: (Observable), +A] extends Source[A], Named

This trait represents a reactive value that can be subscribed to.

It has only one direct subtype, Observable, which in turn has two direct subtypes, EventStream and Signal.

BaseObservable is the same as Observable, it just lives in a separate trait for technical reasons (the Self type param).

All Observables are lazy. An Observable starts when it gets its first observer (internal or external), and stops when it loses its last observer (again, internal or external).

Basic idea: Lazy Observable only holds references to those children that have any observers (either directly on themselves, or on any of their descendants). What this achieves:

  • Stream only propagates its value to children that (directly or not) have observers
  • Stream calculates its value only once regardless of how many observers / children it has) (so, all streams are "hot" observables)
  • Stream doesn't hold references to Streams that no one observes, allowing those Streams to be garbage collected if they are otherwise unreachable (which they should become when their subscriptions are killed by their owners)

Attributes

Companion
object
Graph
Supertypes
trait Named
trait Source[A]
class Object
trait Matchable
class Any
Known subtypes
trait EventStream[A]
trait WritableStream[A]
class MergeStream[A]
trait MultiParentStream[I, O]
class CombineStreamN[A, Out]
class SampleCombineStreamN[A, Out]
trait SingleParentStream[I, O]
class DebuggerStream[A]
class DistinctStream[A]
class CollectStream[A, B]
class DropStream[A]
class FilterStream[A]
class MapStream[I, O]
class StreamFromSignal[A]
class TakeStream[A]
class DebounceStream[A]
class DelayStream[A]
class SyncDelayStream[A]
class ThrottleStream[A]
class EventBusStream[A]
class ConcurrentStream[A]
class SwitchStream[I, O]
class JsPromiseStream[A]
class PeriodicStream[A]
class AjaxStream
class FetchStream
trait Observable[A]
trait Signal[A]
trait WritableSignal[A]
trait MultiParentSignal[I, O]
class CombineSignalN[A, Out]
class SampleCombineSignalN[A, Out]
trait SingleParentSignal[I, O]
class DebuggerSignal[A]
class DistinctSignal[A]
class MapSignal[I, O]
class DerivedVarSignal[A, B]
class ObservedSignal[A]
class ScanLeftSignal[A, B]
class SignalFromStream[A]
class SplitSignal[M, Input, Output, Key]
class SwitchSignal[A]
class Val[A]
class JsPromiseSignal[A]
trait StrictSignal[A]
trait OwnedSignal[A]
trait SyncObservable[A]
trait CustomSource[A]
Show all

Members list

Value members

Abstract methods

def addObserver(observer: Observer[A])(implicit owner: Owner): Subscription

Subscribe an external observer to this observable

Subscribe an external observer to this observable

Attributes

def debugWith(debugger: Debugger[A]): Self[A]

Create a new observable that listens to this one and has a debugger attached.

Create a new observable that listens to this one and has a debugger attached.

Use the resulting observable in place of the original observable in your code. See docs for details.

There are more convenient methods available implicitly from DebuggableObservable and DebuggableSignal, such as debugLog(), debugSpyEvents(), etc.

Attributes

def distinctTry(isSame: (Try[A], Try[A]) => Boolean): Self[A]

Distinct all values (both events and errors) using a comparison function

Distinct all values (both events and errors) using a comparison function

Attributes

def map[B](project: A => B): Self[B]

Value parameters

project

Note: guarded against exceptions

Attributes

def recover[B >: A](pf: PartialFunction[Throwable, Option[B]]): Self[B]

Value parameters

pf

Note: guarded against exceptions

Attributes

def recoverToEither: Self[Either[Throwable, A]]

Convert this to an observable that emits Left(err) instead of erroring

Convert this to an observable that emits Left(err) instead of erroring

Attributes

def recoverToTry: Self[Try[A]]

Convert this to an observable that emits Failure(err) instead of erroring

Convert this to an observable that emits Failure(err) instead of erroring

Attributes

Concrete methods

def distinct: Self[A]

Distinct events (but keep all errors) by == (equals) comparison

Distinct events (but keep all errors) by == (equals) comparison

Attributes

def distinctBy(key: A => Any): Self[A]

Distinct events (but keep all errors) by matching key Note: key(event) might be evaluated more than once for each event

Distinct events (but keep all errors) by matching key Note: key(event) might be evaluated more than once for each event

Attributes

def distinctByFn(isSame: (A, A) => Boolean): Self[A]

Distinct events (but keep all errors) using a comparison function

Distinct events (but keep all errors) using a comparison function

Attributes

def distinctByRef(implicit ev: A <:< AnyRef): Self[A]

Distinct events (but keep all errors) by reference equality (eq)

Distinct events (but keep all errors) by reference equality (eq)

Attributes

def distinctErrors(isSame: (Throwable, Throwable) => Boolean): Self[A]

Distinct errors only (but keep all events) using a comparison function

Distinct errors only (but keep all events) using a comparison function

Attributes

final override def equals(obj: Any): Boolean

Airstream may internally use Scala library functions which use == or hashCode for equality, for example List.contains. Comparing observables by structural equality pretty much never makes sense, yet it's not that hard to run into that, all you need is to create a case class subclass, and the Scala compiler will generate a structural-equality equals and hashCode methods for you behind the scenes.

Airstream may internally use Scala library functions which use == or hashCode for equality, for example List.contains. Comparing observables by structural equality pretty much never makes sense, yet it's not that hard to run into that, all you need is to create a case class subclass, and the Scala compiler will generate a structural-equality equals and hashCode methods for you behind the scenes.

To prevent that, we make equals and hashCode methods final, using the default implementation (which is reference equality).

Attributes

Definition Classes
Any
def flatMap[B, Inner[_], Output <: (Observable)](project: A => Inner[B])(implicit strategy: SwitchingStrategy[Self, Inner, Output], allowFlatMap: AllowFlatMap): Output[B]

#WARNING: DO NOT USE THIS METHOD. See https://github.com/raquo/Airstream/#flattening-observables

#WARNING: DO NOT USE THIS METHOD. See https://github.com/raquo/Airstream/#flattening-observables

Attributes

def flatMapCustom[B, Inner[_], Output <: (Observable)](project: A => Inner[B])(strategy: FlattenStrategy[Self, Inner, Output]): Output[B]

Value parameters

project

Note: guarded against exceptions

Attributes

def flatMapMerge[B, Inner[_], Output <: (Observable)](project: A => Inner[B])(implicit strategy: MergingStrategy[Self, Inner, Output]): Output[B]

Value parameters

project

Note: guarded against exceptions

Attributes

def flatMapSwitch[B, Inner[_], Output <: (Observable)](project: A => Inner[B])(implicit strategy: SwitchingStrategy[Self, Inner, Output]): Output[B]

Value parameters

project

Note: guarded against exceptions

Attributes

def flatMapTo[B, Inner[_], Output <: (Observable)](s: Inner[B])(implicit strategy: SwitchingStrategy[Self, Inner, Output]): Output[B]

Alias to flatMapSwitch(_ => s)

Alias to flatMapSwitch(_ => s)

Attributes

def flatMapWithStatus[B](project: A => EventStream[B]): Self[Status[A, B]]

Based on flatMapSwitch, but tracks the status of input and output to flatMap. See Status.

Based on flatMapSwitch, but tracks the status of input and output to flatMap. See Status.

Attributes

def flatMapWithStatus[B](innerStream: => EventStream[B]): Self[Status[A, B]]

Shorthand for flatMapWithStatus(_ => innerStream).

Shorthand for flatMapWithStatus(_ => innerStream).

Attributes

def foreach(onNext: A => Unit)(implicit owner: Owner): Subscription

Create an external observer from a function and subscribe it to this observable.

Create an external observer from a function and subscribe it to this observable.

Note: since you won't have a reference to the observer, you will need to call Subscription.kill() to unsubscribe

Attributes

final override def hashCode(): Int

Force reference equality checks. See comment for equals.

Force reference equality checks. See comment for equals.

Attributes

Definition Classes
Any
def mapTo[B](value: => B): Self[B]

value is passed by name, so it will be evaluated whenever the Observable fires. Use it to sample mutable values (e.g. myInput.ref.value in Laminar).

value is passed by name, so it will be evaluated whenever the Observable fires. Use it to sample mutable values (e.g. myInput.ref.value in Laminar).

See also: mapToStrict

Value parameters

value

Note: guarded against exceptions

Attributes

def mapToStrict[B](value: B): Self[B]

value is evaluated strictly, only once, when this method is called.

value is evaluated strictly, only once, when this method is called.

See also: mapTo

Attributes

def mapToUnit: Self[Unit]
def matchStreamOrSignal[B](ifStream: EventStream[A] => B, ifSignal: Signal[A] => B): B
def recoverIgnoreErrors: Self[A]
def tapEach[U](f: A => U): Self[A]

Execute a side effecting callback every time the observable emits. If it's a signal, it also runs when its initial value is evaluated.

Execute a side effecting callback every time the observable emits. If it's a signal, it also runs when its initial value is evaluated.

Note: some signals such as stream.startWith or signal.composeAll have cacheInitialValue config, which could affect the number of times this callback is called in cases when you re-start a signal that was previously started, but has never emitted events before. In such cases, if cacheInitialValue == false (the default) , it will cause the signal's initial value to be re-evaluated, and this will in turn trigger the provided tapEach callback.

See com.raquo.airstream.misc.SignalFromStream

// #TODO[API] How to better type this? Note: Do not provide a callback that returns a LAZY value such as EventStream, it will not be started. I may eventually add a flatTapEach method for this.

Note: Calling tapEach on an observable does not add observers to it. The callback will only run if something else is listening to the observable.

Note: The primary method of running side effects in Airstream is putting them into Observers. In general, it's good practice to keep Observables themselves free of side effects. Airstream is actually pretty good at handling non-"pure" observables, but it's better to have such separation of concerns for your own sanity and the code's predictability / maintainability.

Note: This method is called tapEach for consistency with Scala collections. Scala also has a general tap method available by importing util.chaining.*.

Attributes

def toSignalIfStream[B >: A](ifStream: EventStream[A] => Signal[B]): Signal[B]
def toStreamIfSignal[B >: A](ifSignal: Signal[A] => EventStream[B]): EventStream[B]
def toWeakSignal: Signal[Option[A]]

Convert this observable to a signal of Option[A]. If it is a stream, set initial value to None.

Convert this observable to a signal of Option[A]. If it is a stream, set initial value to None.

Attributes

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.

Attributes

Inherited from:
Named
final def displayName: String

Attributes

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

Attributes

Inherited from:
Named

Attributes

Inherited from:
Source
final override def toString: String

Override defaultDisplayName instead of this, if you need to.

Override defaultDisplayName instead of this, if you need to.

Attributes

Definition Classes
Named -> Any
Inherited from:
Named