# cp.rx.BehaviorSubject

A Subject that tracks its current value. Provides an accessor to retrieve the most recent pushed value, and all subscribers immediately receive the latest value.


# API Overview

Methods - API calls which can only be made on an object returned by a constructor

  • create
  • getValue
  • onNext
  • subscribe

# API Documentation

# Methods

# create

Signature cp.rx.BehaviorSubject.create(...) -> cp.rx.BehaviorSubject
Type Method
Description Creates a new BehaviorSubject.
Parameters
  • ... - The initial values.
Returns
  • The new BehaviorSubject.
Notes None
Examples None
Source src/extensions/cp/rx/BehaviorSubject.lua line 15

# getValue

Signature cp.rx.BehaviorSubject:getValue() -> anything
Type Method
Description Returns the last value emitted by the BehaviorSubject, or the initial value passed to the constructor if nothing has been emitted yet.
Parameters
  • None
Returns
  • The last value.
Notes
  • You can also call the BehaviorSubject as a function to retrieve the value. E.g. mySubject().
Examples None
Source src/extensions/cp/rx/BehaviorSubject.lua line 80

# onNext

Signature cp.rx.BehaviorSubject:onNext(...) -> nil
Type Method
Description Pushes zero or more values to the BehaviorSubject. They will be broadcasted to all Observers.
Parameters
  • ... - The values to send.
Returns
  • None
Notes None
Examples None
Source src/extensions/cp/rx/BehaviorSubject.lua line 66

# subscribe

Signature cp.rx.BehaviorSubject:subscribe(observer, onError, onCompleted) -> cp.rx.Reference
Type Method
Description Creates a new Observer and attaches it to the BehaviorSubject. Immediately broadcasts the most recent value to the Observer.
Parameters
  • observer - The Observer subscribing, or the function called when the BehaviorSubject produces a value.
  • onError - A function called when the BehaviorSubject terminates due to an error.
  • onCompleted - A function called when the BehaviorSubject completes normally.
Returns
Notes None
Examples None
Source src/extensions/cp/rx/BehaviorSubject.lua line 37