reative ui

22
Reactive UI Mike Bluestein Developer Evangelist Xamarin [email protected] @mikebluestein CT Code Camp 5/17/2014

Upload: mike-bluestein

Post on 10-May-2015

631 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Reative UI

Reactive UIMike Bluestein

Developer Evangelist Xamarin [email protected]

@mikebluestein !!!!

CT Code Camp 5/17/2014

Page 2: Reative UI

Agenda

• Reactive Extensions for .NET

• ReactiveUI

Page 3: Reative UI

Reactive Programming

Push instead of Pull

Page 4: Reative UI

Reactive Extensions (Rx)

Page 5: Reative UI

–Erik Meijer

“Rx is a library for composing asynchronous and event-based programs using observable

collections.”

Page 6: Reative UI

Reactive UI

Cross-Platform MVVM built on Rx

Page 7: Reative UI

Rx Basics

Page 8: Reative UI

Duality• IObserveable/

IObserver

• dual to IEnumerable/IEnumerator

• represent a data source and a listener, respectively

Page 9: Reative UI

Observable

• IObservable<T> - async data stream that can be observed

• Subscribe - similar to registering an event handler

Page 10: Reative UI

Observer

• IObserver<T> - observe an IObservable<T>

• OnNext, OnCompleted, OnError

Page 11: Reative UI

Observable vs. Events• Declare, Publish, Subscribe

• Subject, OnNext, Subscribe

• Subscribe can take delegates for IObserver methods

• Observable.FromEventPattern<T>

• Returns IEvent objects containing the sender and event arguments

Page 12: Reative UI

Queries

• LINQ methods added to IObservable

Page 13: Reative UI

Queries

myObservable.Throttle(…) .Select(x => …) .Where(x => …) .Subscribe(…)

Page 14: Reative UI

Observable Composition

Dragging event composed of mouse button and mouse move events: !IObservable<Event<MouseEventArgs>> draggingEvent =      from mouseLeftDownEvent in control.GetMouseLeftDown()      from mouseMoveEvent in control.GetMouseMove().Until(control.GetMouseLeftUp())      select mouseMoveEvent;

from http://www.hanselman.com/blog/ReactiveExtensionsRxIsNowOpenSource.aspx

Page 15: Reative UI

Reactive UI

Page 16: Reative UI

–Paul Betts

“ReactiveUI is a cross-platform MVVM framework, built around the Reactive

Extensions”

Page 17: Reative UI

MVVM on Rx

• ViewModel

• Command

• Binding

• Property Change Notification

Page 18: Reative UI

ReactiveObject

• Base class for view models

• Observables for property change notifications

Page 19: Reative UI

Bindings

• IViewFor<T> - routing and binding on views

• Bind ( … )

• OneWayBind ( … )

Page 20: Reative UI

ReactiveCommand

• Registers async method to be called when command is executed

Page 21: Reative UI

DemoReactiveTableViewController

Page 22: Reative UI

Resources• Rx on MSDN

• http://msdn.microsoft.com/en-us/data/gg577609

• Rx source on Codeplex

• https://rx.codeplex.com

• ReactiveUI source on Github

• https://github.com/reactiveui/ReactiveUI