Top Banner
Reactive Xamarin Olexandr Leuschenko uamobile 2016
49

Reactive Xamarin. UA Mobile 2016.

Apr 07, 2017

Download

Software

UA Mobile
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Reactive Xamarin. UA Mobile 2016.

Reactive Xamarin

Olexandr Leuschenko uamobile 2016

Page 2: Reactive Xamarin. UA Mobile 2016.

Everything is an

object

Alan Kay

Page 3: Reactive Xamarin. UA Mobile 2016.

Everything is a stream of objects!

Page 4: Reactive Xamarin. UA Mobile 2016.

Streams are

observable

Page 5: Reactive Xamarin. UA Mobile 2016.

represent data as streams with observables !

query with LINQ !

rule the concurrency with schedulers

Page 6: Reactive Xamarin. UA Mobile 2016.

Observables + LINQ + Schedulers

Page 7: Reactive Xamarin. UA Mobile 2016.

Rx =Observables + LINQ + Schedulers

Page 8: Reactive Xamarin. UA Mobile 2016.

Reactive Xamarin =Rx + Xamarin

Page 9: Reactive Xamarin. UA Mobile 2016.

Q & A

Page 10: Reactive Xamarin. UA Mobile 2016.

Agenda

• What is Observable?

• What about LINQ?

• Master time with Schedulers

• Why bother?

Page 11: Reactive Xamarin. UA Mobile 2016.

Agenda

• What is Observable?

• What about LINQ?

• Master time with Schedulers

• Why bother?

Page 12: Reactive Xamarin. UA Mobile 2016.
Page 13: Reactive Xamarin. UA Mobile 2016.
Page 14: Reactive Xamarin. UA Mobile 2016.

stream is a collection

collection is a stream

Page 15: Reactive Xamarin. UA Mobile 2016.

IEnumerator

• object Current { get; }

• bool MoveNext ();

• void Reset ();

Page 16: Reactive Xamarin. UA Mobile 2016.
Page 17: Reactive Xamarin. UA Mobile 2016.

PULL

Page 18: Reactive Xamarin. UA Mobile 2016.

PULL

Page 19: Reactive Xamarin. UA Mobile 2016.

PUSH

Page 20: Reactive Xamarin. UA Mobile 2016.

IObserver

• void OnNext (T value);

• void OnCompeted ();

• void OnError (Exception exception);

Page 21: Reactive Xamarin. UA Mobile 2016.

PULL vs PUSH

Page 22: Reactive Xamarin. UA Mobile 2016.

SYNC vs ASYNC

Page 23: Reactive Xamarin. UA Mobile 2016.

I have TPL

Page 24: Reactive Xamarin. UA Mobile 2016.

Single Value Multiple Values

SYNC T IEnumerable<T>

ASYNC Task<T> IObservable<T>

Page 25: Reactive Xamarin. UA Mobile 2016.

How to create Observables? • Factory Methods ◦ Observable.Return ◦ Observable.Empty ◦ Observable.Never ◦ Observable.Throw ◦ Observable.Create • Unfold methods ◦ Observable.Range ◦ Observable.Interval ◦ Observable.Timer ◦ Observable.Generate • Paradigm Transition ◦ Observable.Start ◦ Observable.FromEventPattern ◦ Task.ToObservable ◦ Task<T>.ToObservable ◦ IEnumerable<T>.ToObservable ◦ Observable.FromAsyncPattern

Page 26: Reactive Xamarin. UA Mobile 2016.

Tiny demo

Page 27: Reactive Xamarin. UA Mobile 2016.

Agenda

• What is Observable?

• What about LINQ?

• Master time with Schedulers

• Why bother?

Page 28: Reactive Xamarin. UA Mobile 2016.

Reactive LINQ is like LINQ, but Reactive

Page 29: Reactive Xamarin. UA Mobile 2016.

LINQ & Observables

Page 30: Reactive Xamarin. UA Mobile 2016.

RxMarbleshttp://rxmarbles.com

Page 31: Reactive Xamarin. UA Mobile 2016.

Agenda

• What is Observable?

• What about LINQ?

• Master time with Schedulers

• Why bother?

Page 32: Reactive Xamarin. UA Mobile 2016.

Events are single-thread

Page 33: Reactive Xamarin. UA Mobile 2016.

Rx is single-thread

Page 34: Reactive Xamarin. UA Mobile 2016.

Schedulers• ImmediateScheduler — will start the specified

action immediately

• CurrentThreadScheduler — will schedule action to be performed on the thread that makes the original call

• DispatcherScheduler — will scheduler action on the current Dispatcher

• …

Page 35: Reactive Xamarin. UA Mobile 2016.

TimeScheduler

Page 36: Reactive Xamarin. UA Mobile 2016.

Teeny-weeny Demo

Page 37: Reactive Xamarin. UA Mobile 2016.

Agenda

• What is Observable?

• What about LINQ?

• Master time with Schedulers

• Why bother?

Page 38: Reactive Xamarin. UA Mobile 2016.

Reactive UI• UI-friendly extension methods

• Base ViewModel

• Base View

• DI

• Logging

• Supports Xamarin.iOS, Xamarin.Android, Xamarin.Mac, Xamarin Forms, WPF, Windows Forms, Windows Phone 8, Windows Store and Universal Windows Platform (UWP)

Page 39: Reactive Xamarin. UA Mobile 2016.

Reactive UI• UI-friendly extension methods

• Base ViewModel

• Base View

• DI

• Logging

• Supports Xamarin.iOS, Xamarin.Android, Xamarin.Mac, Xamarin Forms, WPF, Windows Forms, Windows Phone 8, Windows Store and Universal Windows Platform (UWP)

Page 40: Reactive Xamarin. UA Mobile 2016.

Reactive UI• UI-friendly extension methods

• Base ViewModel

• Base View

• DI

• Logging

• Supports Xamarin.iOS, Xamarin.Android, Xamarin.Mac, Xamarin Forms, WPF, Windows Forms, Windows Phone 8, Windows Store and Universal Windows Platform (UWP)

Page 41: Reactive Xamarin. UA Mobile 2016.
Page 42: Reactive Xamarin. UA Mobile 2016.
Page 43: Reactive Xamarin. UA Mobile 2016.
Page 44: Reactive Xamarin. UA Mobile 2016.

RxLite

• UI-friendly extension methods

• Optional base ViewModel

Page 45: Reactive Xamarin. UA Mobile 2016.

RxLite Simple Rules

• One-Way binding — ObservableAsProperty

• Two-Way binding — property with RaiseAndSetIfChanged

• Command — ReactiveCommand

Page 46: Reactive Xamarin. UA Mobile 2016.

Reactive UI

RxLite

So?

Page 47: Reactive Xamarin. UA Mobile 2016.

Playground demohttps://github.com/OlexaLe/RxLite

Page 48: Reactive Xamarin. UA Mobile 2016.

Thanks!

[email protected]

• http://twitter.com/olexale