Reacting With ReactiveUIAllen GreavesIntelliTect
Technologies System.Reactive           ReactiveUI Can be found on NuGet    Can be found on NuGet   Rx-Main             ...
Namespaces using   System.Reactive using   System.Reactive.Linq using   System.Reactive.Concurrency using   ReactiveUI...
Demo
ToObservable() Converts an enumerable sequence to an observable  sequence Behaves like ToList()
SelectMany( x => … ) Projects a sequence into observable sequences Then flattens these sequences into a sequence
Observable.Start( () => … ) Invokes a function asynchronously
Subscribe( x => … ) Bread and butter of Reactive Kicks off processing of the observable sequence Behaves like ForEach( ...
ObserveOnDispatcher() Marshals asynchronous observables onto the dispatcher  thread Behaves like CurrentDispatcher.Begin...
ReactiveObjectReactiveValidatedObject Provides useful extensions ViewModels as ReactiveObjects Validation   [Validates...
Demo
Select( x => … ) Projects a sequence of elements Behaves like enumerable Select( x => … ) Does not flatten
Observable.Defer( () => … ) Defers function invocation Without it, Select() will go ahead and project all elements
Merge( … ) Merges many sequences into one sequence Limits the number of in-flight threads Used with Observable.Defer
Other Fun Extensions! Delay( … )   Delays the sequence Buffer( … )   Batches input Interval( … )   Sequence of eleme...
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
Observablea = b + c  a is set to the sum of b and c  If b or c updates then a is reevaluated
public interface IObservable<out T>{    IDisposable Subscribe(IObserver<T> observer);}public interface IObserver<in T>{   ...
Demo
this.WhenAny( x => … ) Makes dealing with PropertyChanged notifications easier First real look at events as a sequence
Where( x => … ) Filters elements of a sequence
Demo
new ReactiveCommand( … ) Subscribes to an IObservable for CanExecute()   Makes heavy operations easier Subscribe to the...
UpdateCommand = new ReactiveCommand(  this.WhenAny( x => x.FileNames, x => x.Value )    .Select(item => item != null && it...
What do you get? Loosely coupled code   Everything is built by hooking up observables   Properties can be dumb   Preve...
Resources Reactive Extension Guides   http://msdn.microsoft.com/en-us/data/gg577611 101 samples   http://rxwiki.wikido...
Upcoming SlideShare
Loading in …5
×

Reacting with ReactiveUI

2,194 views

Published on

Published in: Technology, Sports
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,194
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
19
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • 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.
  • Reacting with ReactiveUI

    1. 1. Reacting With ReactiveUIAllen GreavesIntelliTect
    2. 2. Technologies System.Reactive ReactiveUI Can be found on NuGet  Can be found on NuGet  Rx-Main  reactiveui-xaml
    3. 3. Namespaces using System.Reactive using System.Reactive.Linq using System.Reactive.Concurrency using ReactiveUI using ReactiveUI.Xaml
    4. 4. Demo
    5. 5. ToObservable() Converts an enumerable sequence to an observable sequence Behaves like ToList()
    6. 6. SelectMany( x => … ) Projects a sequence into observable sequences Then flattens these sequences into a sequence
    7. 7. Observable.Start( () => … ) Invokes a function asynchronously
    8. 8. Subscribe( x => … ) Bread and butter of Reactive Kicks off processing of the observable sequence Behaves like ForEach( x => … )
    9. 9. ObserveOnDispatcher() Marshals asynchronous observables onto the dispatcher thread Behaves like CurrentDispatcher.BeginInvoke() Necessary for WPF
    10. 10. ReactiveObjectReactiveValidatedObject Provides useful extensions ViewModels as ReactiveObjects Validation  [ValidatesViaMethod(…)]
    11. 11. Demo
    12. 12. Select( x => … ) Projects a sequence of elements Behaves like enumerable Select( x => … ) Does not flatten
    13. 13. Observable.Defer( () => … ) Defers function invocation Without it, Select() will go ahead and project all elements
    14. 14. Merge( … ) Merges many sequences into one sequence Limits the number of in-flight threads Used with Observable.Defer
    15. 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. 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. 17. Observablea = b + c  a is set to the sum of b and c  If b or c updates then a is reevaluated
    18. 18. public interface IObservable<out T>{ IDisposable Subscribe(IObserver<T> observer);}public interface IObserver<in T>{ void OnNext(T value); void OnError(T error); void OnComplete();}
    19. 19. Demo
    20. 20. this.WhenAny( x => … ) Makes dealing with PropertyChanged notifications easier First real look at events as a sequence
    21. 21. Where( x => … ) Filters elements of a sequence
    22. 22. Demo
    23. 23. new ReactiveCommand( … ) Subscribes to an IObservable for CanExecute()  Makes heavy operations easier Subscribe to the IObservable to receive command elements
    24. 24. UpdateCommand = new ReactiveCommand( this.WhenAny( x => x.FileNames, x => x.Value ) .Select(item => item != null && item.Any()) );UpdateCommand.Subscribe( (x) => … );
    25. 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
    26. 26. Resources Reactive Extension Guides  http://msdn.microsoft.com/en-us/data/gg577611 101 samples  http://rxwiki.wikidot.com/101samples#toc25 ReactiveUI – Paul Betts  http://www.reactiveui.net/

    ×