Rx – Reactive Extension (part 2)
the previous post discuss the concept of Rx (Reactive Framework Extension),
this post will focus on some basic practice.
In this post we will create small WPF application that got images from different
image feeds providers (the source code can be found here).
The application layout is described in the following diagram.
the image data will be pushed into the PhotoDataSourceProvider class which implement IObserver.
the class will take the pushed data and expose it to the UI through the DataSourceProvider overrides.
DataSourceProvider is used as mediator between the UI and the Feeders in order to make the UI data thread safe.
In short the IObserver is where the data get pushed.
The feeders implement IObservable
all feeders inherit from ImageFeederBase.
IObservable expose the Subscribe method, which can be use for subscribing the
PhotoDataSourceProvider (because it is an observer).
this is how the PhotoDataSourceProvider constructor look like:
it subscribing itself for different feeders.
then whenever the feeder Has new image, Complete or Has Error
the PhotoDataSourceProvider will be notify through it IObserver implementation.
the Rx is using the IObservable and IObserver in order to formalize push based operation.
the IObservable is the push supplier, while the IObserver is the push target.
IObserver can be subscribe to one or more IObservable.
the source code can be found here.