SlideShare une entreprise Scribd logo
1  sur  26
Reacting With ReactiveUI
Allen Greaves
IntelliTect
Technologies
 System.Reactive           ReactiveUI
 Can be found on NuGet    Can be found on NuGet
   Rx-Main                  reactiveui-xaml
Namespaces
 using   System.Reactive
 using   System.Reactive.Linq
 using   System.Reactive.Concurrency
 using   ReactiveUI
 using   ReactiveUI.Xaml
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( x => … )
ObserveOnDispatcher()
 Marshals asynchronous observables onto the dispatcher
  thread
 Behaves like CurrentDispatcher.BeginInvoke()
 Necessary for WPF
ReactiveObject
ReactiveValidatedObject
 Provides useful extensions
 ViewModels as ReactiveObjects
 Validation
   [ValidatesViaMethod(…)]
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 elements occurring on a set interval
 Throttle( … )
   Ignores values during a specified TimeSpan
 Timestamp( … )
   Timestamps elements in a sequence
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>
{
    void OnNext(T value);
    void OnError(T error);
    void OnComplete();
}
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 IObservable to receive command elements
UpdateCommand = new ReactiveCommand(
  this.WhenAny( x => x.FileNames, x => x.Value )
    .Select(item => item != null && item.Any()) );

UpdateCommand.Subscribe( (x) => … );
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
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/

Contenu connexe

Tendances

BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)Sylvain Hallé
 
Call by value and call by reference and varaiable length arguments
Call by value and call by reference and  varaiable length argumentsCall by value and call by reference and  varaiable length arguments
Call by value and call by reference and varaiable length argumentsvishal choudhary
 
Mcrl2 by kashif.namal@gmail.com, adnanskyousafzai@gmail.com
Mcrl2 by kashif.namal@gmail.com, adnanskyousafzai@gmail.comMcrl2 by kashif.namal@gmail.com, adnanskyousafzai@gmail.com
Mcrl2 by kashif.namal@gmail.com, adnanskyousafzai@gmail.comkashif kashif
 
JavaScript ES10 and React Js Introduction
JavaScript ES10 and React Js IntroductionJavaScript ES10 and React Js Introduction
JavaScript ES10 and React Js IntroductionAmanpreet Singh
 
RxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowRxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowViliam Elischer
 
The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212Mahmoud Samir Fayed
 
Objective-C Runtime overview
Objective-C Runtime overviewObjective-C Runtime overview
Objective-C Runtime overviewFantageek
 
.Net Enterprise Services and their Implementations
.Net Enterprise Services and their Implementations.Net Enterprise Services and their Implementations
.Net Enterprise Services and their ImplementationsKashif Aleem
 
Java agents are watching your ByteCode
Java agents are watching your ByteCodeJava agents are watching your ByteCode
Java agents are watching your ByteCodeRoman Tsypuk
 
Ejercicios
EjerciciosEjercicios
Ejerciciosleonharo
 
Better react/redux apps using redux-saga
Better react/redux apps using redux-sagaBetter react/redux apps using redux-saga
Better react/redux apps using redux-sagaYounes (omar) Meliani
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak MeetUp
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)Sylvain Hallé
 
Promise of an API
Promise of an APIPromise of an API
Promise of an APIMaxim Zaks
 
The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196Mahmoud Samir Fayed
 

Tendances (20)

BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
 
Call by value and call by reference and varaiable length arguments
Call by value and call by reference and  varaiable length argumentsCall by value and call by reference and  varaiable length arguments
Call by value and call by reference and varaiable length arguments
 
Mcrl2 by kashif.namal@gmail.com, adnanskyousafzai@gmail.com
Mcrl2 by kashif.namal@gmail.com, adnanskyousafzai@gmail.comMcrl2 by kashif.namal@gmail.com, adnanskyousafzai@gmail.com
Mcrl2 by kashif.namal@gmail.com, adnanskyousafzai@gmail.com
 
JavaScript ES10 and React Js Introduction
JavaScript ES10 and React Js IntroductionJavaScript ES10 and React Js Introduction
JavaScript ES10 and React Js Introduction
 
Java 7 new features
Java 7 new featuresJava 7 new features
Java 7 new features
 
RxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowRxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrow
 
The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212The Ring programming language version 1.10 book - Part 101 of 212
The Ring programming language version 1.10 book - Part 101 of 212
 
Objective-C Runtime overview
Objective-C Runtime overviewObjective-C Runtime overview
Objective-C Runtime overview
 
.Net Enterprise Services and their Implementations
.Net Enterprise Services and their Implementations.Net Enterprise Services and their Implementations
.Net Enterprise Services and their Implementations
 
Reactive x
Reactive xReactive x
Reactive x
 
Java agents are watching your ByteCode
Java agents are watching your ByteCodeJava agents are watching your ByteCode
Java agents are watching your ByteCode
 
Ejercicios
EjerciciosEjercicios
Ejercicios
 
Better react/redux apps using redux-saga
Better react/redux apps using redux-sagaBetter react/redux apps using redux-saga
Better react/redux apps using redux-saga
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro Bignyak
 
JS Anti Patterns
JS Anti PatternsJS Anti Patterns
JS Anti Patterns
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)
 
Promise of an API
Promise of an APIPromise of an API
Promise of an API
 
Using zone.js
Using zone.jsUsing zone.js
Using zone.js
 
Loops (1)
Loops (1)Loops (1)
Loops (1)
 
The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196The Ring programming language version 1.7 book - Part 91 of 196
The Ring programming language version 1.7 book - Part 91 of 196
 

Similaire à Reacting with ReactiveUI

Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架jeffz
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015Codemotion
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Mario Fusco
 
.Net 4.0 Threading and Parallel Programming
.Net 4.0 Threading and Parallel Programming.Net 4.0 Threading and Parallel Programming
.Net 4.0 Threading and Parallel ProgrammingAlex Moore
 
Reactive Extensions (Rx)
Reactive Extensions (Rx)Reactive Extensions (Rx)
Reactive Extensions (Rx)Mark Allan
 
Sync with async
Sync with  asyncSync with  async
Sync with asyncprabathsl
 
Understanding reactive programming with microsoft reactive extensions
Understanding reactive programming  with microsoft reactive extensionsUnderstanding reactive programming  with microsoft reactive extensions
Understanding reactive programming with microsoft reactive extensionsOleksandr Zhevzhyk
 
Parallel Processing
Parallel ProcessingParallel Processing
Parallel ProcessingRTigger
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simplerAlexander Mostovenko
 

Similaire à Reacting with ReactiveUI (20)

Rx – reactive extensions
Rx – reactive extensionsRx – reactive extensions
Rx – reactive extensions
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
 
Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
Rxjs ngvikings
Rxjs ngvikingsRxjs ngvikings
Rxjs ngvikings
 
Reactive Extensions
Reactive ExtensionsReactive Extensions
Reactive Extensions
 
Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
 
.Net 4.0 Threading and Parallel Programming
.Net 4.0 Threading and Parallel Programming.Net 4.0 Threading and Parallel Programming
.Net 4.0 Threading and Parallel Programming
 
Reactive Extensions (Rx)
Reactive Extensions (Rx)Reactive Extensions (Rx)
Reactive Extensions (Rx)
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
Sync with async
Sync with  asyncSync with  async
Sync with async
 
Understanding reactive programming with microsoft reactive extensions
Understanding reactive programming  with microsoft reactive extensionsUnderstanding reactive programming  with microsoft reactive extensions
Understanding reactive programming with microsoft reactive extensions
 
Parallel Processing
Parallel ProcessingParallel Processing
Parallel Processing
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
 

Dernier

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Dernier (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

Reacting with ReactiveUI

  • 1. Reacting With ReactiveUI Allen Greaves IntelliTect
  • 2. Technologies System.Reactive ReactiveUI  Can be found on NuGet  Can be found on NuGet  Rx-Main  reactiveui-xaml
  • 3. Namespaces  using System.Reactive  using System.Reactive.Linq  using System.Reactive.Concurrency  using ReactiveUI  using ReactiveUI.Xaml
  • 5. ToObservable()  Converts an enumerable sequence to an observable sequence  Behaves like ToList()
  • 6. SelectMany( x => … )  Projects a sequence into observable sequences  Then flattens these sequences into a sequence
  • 7. Observable.Start( () => … )  Invokes a function asynchronously
  • 8. Subscribe( x => … )  Bread and butter of Reactive  Kicks off processing of the observable sequence  Behaves like ForEach( x => … )
  • 9. ObserveOnDispatcher()  Marshals asynchronous observables onto the dispatcher thread  Behaves like CurrentDispatcher.BeginInvoke()  Necessary for WPF
  • 10. ReactiveObject ReactiveValidatedObject  Provides useful extensions  ViewModels as ReactiveObjects  Validation  [ValidatesViaMethod(…)]
  • 11. Demo
  • 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
  • 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. Demo
  • 20. this.WhenAny( x => … )  Makes dealing with PropertyChanged notifications easier  First real look at events as a sequence
  • 21. Where( x => … )  Filters elements of a sequence
  • 22. Demo
  • 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
  • 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/

Notes de l'éditeur

  1. You’re tasked with reading all lines from every text file in a folder and the display its contents.
  2. Functions like calling CurrentDispatcher.BeginInvoke() inside of the Subscribe.
  3. 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.
  4. 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.
  5. 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.
  6. 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.