12. Select( x => … )
Projects a sequence of elements
Behaves like enumerable Select( x => … )
Does not flatten
13. Observable.Defer( () => … )
Defers function invocation
Without it, Select() will go ahead and project all elements
14. Merge( … )
Merges many sequences into one sequence
Limits the number of in-flight threads
Used with Observable.Defer
15. Other Fun Extensions!
Delay( … )
Delays the sequence
Buffer( … )
Batches input
Interval( … )
Sequence of elements occurring on a set interval
Throttle( … )
Ignores values during a specified TimeSpan
Timestamp( … )
Timestamps elements in a sequence
16. Non-Observable
a = b + c
a is set to the sum of b and c
If b or c updates then a remains the same
17. Observable
a = b + c
a is set to the sum of b and c
If b or c updates then a is reevaluated
23. new ReactiveCommand( … )
Subscribes to an IObservable for CanExecute()
Makes heavy operations easier
Subscribe to the IObservable to receive command elements
24. UpdateCommand = new ReactiveCommand(
this.WhenAny( x => x.FileNames, x => x.Value )
.Select(item => item != null && item.Any()) );
UpdateCommand.Subscribe( (x) => … );
25. What do you get?
Loosely coupled code
Everything is built by hooking up observables
Properties can be dumb
Prevents having to put code in the getters and setters of bound
properties
Easier and more powerful event handling
Handling the PropertyChanged event is a mess
Unit Testing
Since our code is much more loosely coupled we can test easier
Scheduler
You’re tasked with reading all lines from every text file in a folder and the display its contents.
Functions like calling CurrentDispatcher.BeginInvoke() inside of the Subscribe.
It turns out that the spec that mapped out the requirements you were tasked with actually had a key detail left out of it. (This, of course, rarely happens). Apparently there will be many thousands of files that will need to be read in. They understand the risks involved with how the ui will slow down with this much information.
Upon subscribing to an observable you can specify what to do on the next element of the sequence occuring, on erroring of the sequence, and on completion of the sequence.
So it turns out that having all of this information once is difficult to work with. And instead the business wants to type in each filename to process.
The business is asking for one last change and it’s a minor one. They want to type all of the files they care about into one large textbox. Also, they decided that not having a button is a bad design decision.