Skip to content

Day 09 Rx.Net part 3

Kobi Hari edited this page Sep 17, 2020 · 1 revision

Day 09 - Reactive X - Part 3

Projects:

Fun With Rx.Net Programming reative ui using Rx Operators

Side Effects, Logging and Debugging

  • We used the The Do Operator to create log and allow debugging
    • We noticed that Do does not actually do anything until the observable is subscribed to
    • We understood the difference between Do and Subscribe
  • We saw how to create, and how not to create operators of our own

Observable Temperature

  • We used subjects as HUB and created a demo where the subject turns a cold observable to hot
  • We distinctify between the two roles that the subject serves when used as a hub
    • It publishes the same events to all observers
    • It "activates" the source by subscribing to it
  • We got familiar with the Publish operator which serves like a Subject
    • Publish turns a cold observable to hot
    • The actual subscription is deffered until the Connect method is called
    • You can use Publish(initialValue) to create a BehaviorPublisher that behaves like a BehaviorSubject
    • You can disconnect using the IDisposable returned from the Connect method
    • You can use PublishLast to create a publisher that acts like AsyncSubject
  • We used the .Publish().Refcount() to create a publisher that automatically connects to source when the first observer subscribes to it
  • We subscribed the same subject to multiple observables
    • We discovered that the subject completes as soon as one of the observables completes
    • Which makes it a bad choice to use as a hot merging tool
    • Instead we can use Merge
    • And if we want a hot merged observable we will use Merge().Publish().RefCount()
  • We turned a Hot Observable into Cold by using the Replay Operator

Observable Aggregation

  • We saw how to use Sum, Count, Max, ToList - All reactive!!!
  • We saw that they return a Scalar Observable - an observable that returns a single value
  • We learned how to use Aggregate to create a general aggregator
  • We saw the Scan Operator and realized it is just like Aggregate except it returns sub results after each source event.

Creating 2'nd order observables

  • We used the Select Operator to create an Observable of Observables
  • We saw that we can also use GroupBy and Window to transfer a flat observable into second order one.
  • We saw that Buffer is similiar to Window except that it returns IObservable<IEnumerable<T>>

Partitioning and Combining

  • We saw the The Zip Operator that combines 2 (or more) observables by matching events with the same index and combining them togher using a projection method
  • We saw the CombineLatest Operator and realized it is like Zip except that it yields a combined event whenever either operand yields an event.
  • We saw the WithLatestFrom Operator which is like CombineLatest but not symmetrical, so it only yields events when the first observable yields them.

Observable Chaining

  • We saw that the Concat Operator can be used to chain 2 observables
    • We realized that it has very different results when the observables are hot
  • We also used the Repeat operator to resubscribe to the same observable
  • We saw that Merge and Concat have a version where they apply on an IObservable<IObservable<T>> rather than on a fixed number of observables.

Observable Selection

  • We saw that we can use the Switch operator to create an observable that returns always subscribes to the last inner observable that is created
  • We saw that we can use the Amb operator to create an observable that only stays subscribed with the first observable that yields an event.