Bus

The Bus class represents a special type of Signal that can broadcast values to its observers. You can connect other signals to a bus, as well as manually emit values and errors.

new Bus()

Extends Signal

Example
import { Bus, Signal } from 'bulb'

const bus = new Bus()

// Subscribe to the bus and log emitted values to the console.
bus.subscribe(console.log)

// Emit a value on the bus.
bus.next(0)

// Connect a signal to the bus.
const s = Signal.of(1, 2, 3)
bus.connect(s)
Instance Members
next(value)
error(e)
complete()
connect(signal)

Signal

The Signal class represents a time-varying source of values – for example, the value of a text input, a periodic timer, or even the position of the mouse pointer in the browser window.

When creating a new signal you must provide a mount function, which when called will connect the signal to a source of values. This function will only be called once an observer has subscribed to the signal. This is because signals are lazy – they don't bother emitting values until an observer is listening.

The mount function takes an emit object as its only argument. This allows the signal to emit values:

  • emit.next(a) - Emits the value a.
  • emit.error(e) - Emits the error e.
  • emit.complete() - Marks the signal as complete.

The mount function can also optionally return an unmount function, which when called will disconnect the signal from its source of values. This function will only be called once all observers have unsubscribed from the signal.

new Signal(mount: Function)
Parameters
mount (Function) The function that is used to connect the signal with a source of values. It can optionally return an unmount function.
Example
import { Signal } from 'bulb'

// Create a signal that emits the value 'foo' every second.
const s = new Signal(emit => {
  // Start the timer and emit a value whenever the timer fires.
  const id = setInterval(() => emit.next('foo'), 1000)

  // Return a function to be called when the signal is unmounted.
  return () => clearInterval(id)
})

// Subscribe to the signal and log emitted values to the console.
const subscription = s.subscribe(console.log)

// When we are done, we can unsubscribe from the signal.
subscription.unsubscribe()
Static Members
concat(signals)
empty()
from(iterable)
fromCallback(f)
fromEvent(type, target, options?)
fromPromise(p)
merge(signals)
never()
of(values)
periodic(n)
throwError(e)
zip(signals)
zipWith(f, signals)
Instance Members
all(p)
always(value)
any(p)
append(values)
apply(signals)
buffer(n)
catchError(f)
concat(signals)
concatMap(f)
cycle(values)
debounce(n)
dedupe()
dedupeWith(f)
delay(n)
drop(n)
dropUntil(signal)
dropWhile(p)
encode(signals)
endWith(value)
filter(p)
first()
fold(f, initialValue)
hold(signal)
last()
map(f)
merge(signals)
prepend(values)
sample(signal)
scan(f, initialValue)
sequential(values)
startWith(value)
stateMachine(f, initialState)
subscribe(onNext?, onError?, onComplete?)
switchLatest()
switchMap(f)
take(n)
takeUntil(signal)
takeWhile(p)
throttle(n)
zip(signals)
zipWith(f, signals)

Subscription

The Subscription class represents an observer who has subscribed to a Signal.

new Subscription(emit: Object, unsubscribe: Function)
Parameters
emit (Object) An emit object.
unsubscribe (Function) An unsubscribe function.
Instance Members
unsubscribe()
closed