toStream

Converts an expression to an observable stream (a.k.a. TC 39 Observable / RxJS observable). The provided expression is tracked by mobx as long as there are subscribers, automatically emitting when new values become available. The expressions respect (trans)actions.

Parameters

  • expression
  • fireImmediately boolean (by default false)

Examples

  1. const user = observable({
  2. firstName: "C.S",
  3. lastName: "Lewis"
  4. })
  5. Rx.Observable
  6. .from(mobxUtils.toStream(() => user.firstname + user.lastName))
  7. .scan(nameChanges => nameChanges + 1, 0)
  8. .subscribe(nameChanges => console.log("Changed name ", nameChanges, "times"))

Returns IObservableStream<T>