Reactive extensions - secondnug
-
Upload
fernando-escolar -
Category
Sports
-
view
2.600 -
download
3
description
Transcript of Reactive extensions - secondnug
Bienvenido al mundo reactivo con: Reactive Extensions (Rx)
Por Fernando Escolar
reactive extensions
contexto
@SecondNug@fernandoescolar
the cloudclient
application
uievent-based
asynchronous communication
reactive extensions
• Basada en flujos de datos y propagación de cambios.
reactive programming
Tradicional Reactiva
@SecondNug@fernandoescolar
reactive extensions
• Microsoft Live Labs - Erik Meijer“Rx es una librería para componer programas asíncronos y basados en eventos usando colecciones observables”
• Dualidad matemática entre el patrón iterator y el observer.
@SecondNug@fernandoescolar
definición
reactive extensions
• Microsoft Live Labs - Erik Meijer“Rx es una librería para componer programas asíncronos y basados en eventos usando colecciones observables”
• Dualidad matemática entre el patrón iterator y el observer.
@SecondNug@fernandoescolar
definición
Rx = Observables + Linq + Schedulers“
reactive extensions
Nuget Web
instalación
@SecondNug@fernandoescolar
reactive extensions
patrón iterator
@SecondNug@fernandoescolar
reactive extensions
patrón observer
@SecondNug@fernandoescolar
reactive extensions
@SecondNug@fernandoescolar
formula
Rx = Observables + Linq + Schedulers“
reactive extensions
ISubject<T>: IObservable<T>,IObserver<T>
Tipos:• Subject<T>• ReplaySubject<T>• BehaviorSubject<T>• AsyncSubject<T>
sujetos
@SecondNug@fernandoescolar
reactive extensions
Rx vs. events
@SecondNug@fernandoescolar
Eventos: Declaración event Action<string> Notified;
Suscripción Action<string> OnNotified = s => Console.WriteLine(s); Notified += OnNotified;
Publicación Notified("hello");
Desuscripción Notified -= OnNotified;
Sujetos: Declaración ISubject<string> Changed = new Subject<string>();
Suscripción var disposable = Changed.Subscribe( s => Console.WriteLine(s));
Publicación Changed.OnNext ("hello");
Desuscripción disposable.Dispose();
reactive extensions
• Create• CreateWithDisposable• Defer• Empty• FromAsyncPattern• FromEvent• Generate• GenerateInSequence• Interval
observable: creadores
@SecondNug@fernandoescolar
• Never• Range• Repeat• Return• Start• StartWith• Throw• Timer• Using
reactive extensions
@SecondNug@fernandoescolar
formula
Rx = Observables + Linq + Schedulers“
reactive extensions
• Dispatcher: Programa en el dispatcher actual. • NewThread: Lo programa en un nuevo hilo.• ThreadPool: Lo encola en la threadPool.• TaskPool: En la Pool de task (Parallel)• Inmediate: Lo ejecuta inmediatamente, sin
programar.• CurrentThread: La programa para ejecutarse
en el hilo actual.
scheduler
@SecondNug@fernandoescolar
reactive extensions
@SecondNug@fernandoescolar
formula
Rx = Observables + Linq + Schedulers“
reactive extensions
• SubscribeOn• SubscribeOnDispatcher• Switch• Synchronize• Take• TakeWhile• Throttle• TimeInterval• Timeout• Timestamp• Until• WaitUntil• Where• Yield• Zip
observable: operadores i.
@SecondNug@fernandoescolar
• Merge• ObserveOn• ObserveOnDispatcher• OnErrorResumeNext• Remotable• RemoveTimeInterval• RemoveTimestamp• Repeat• Retry• Sample• Scan• Select• SelectMany• Skip• SkipWhile• SkipUntil
• Amb• Asynchronous• Buffer• BufferWithTime• Catch• CombineLatest• Concat• Delay• Dematerialize• Do• Finally• GroupBy• Hide• HoldUntilChanged• Let• Materialize
reactive extensions
• Evaluadores: Agregarte And Contains Count First FirstOrDefault GetEnumerator Last LastOrDefault Latest LatestValue LongCount MostRecent MostRecentValue Next NextValue Single SingleOrDefault ToEnumerable
observable: operadores ii.
@SecondNug@fernandoescolar
• Uniones: Join Then
• Otras: Prune Publish Record Replay
reactive extensions
Rx vs. events
@SecondNug@fernandoescolar
Eventos: Declaración event Action<string> Notified;
Suscripción Action<string> OnNotified = s => Console.WriteLine(s); Notified += OnNotified;
Publicación Notified("hello");
Desuscripción Notified -= OnNotified;
Sujetos: Declaración ISubject<string> Changed = new Subject<string>();
Suscripción var disposable = Changed.Subscribe( s => Console.WriteLine(s));
Publicación Changed.OnNext ("hello");
Desuscripción disposable.Dispose();
reactive extensions
Convertir un cualquier evento en observable:
Linq2Events
@SecondNug@fernandoescolar
reactive extensions
Ejemplos útiles en diversas aplicaciones:
- WPF Drag ‘n Drop- Reactive EventAggregator- Twitter
Ejemplos
@SecondNug@fernandoescolar
reactive extensions
ruegos y preguntas
@SecondNug@fernandoescolar
reactive extensions
¡Muchas gracias a todos!
• Agradecimientos: SecondNug y concretamente a Alfredo Fernández Pablo Bouzada Javier Jimenez (rx: first contact)
• Enlaces de interés http://en.wikipedia.org/wiki/Reactive_programming http://en.wikipedia.org/wiki/Observer_pattern http://en.wikipedia.org/wiki/Iterator_pattern http://www.dofactory.com/Patterns/PatternIterator.aspx http://www.minddriven.de/index.php/technology/dot-net/reactive-framework-rx-first-look http://www.silverlightshow.net/items/Using-Reactive-Extensions-in-Silverlight.aspx http://leecampbell.blogspot.com/2010/08/reactive-extensions-for-net.html http://rxwiki.wikidot.com/101samples
despedida
@SecondNug@fernandoescolar