go reactive - manuel vicente vivo

18
Go Reactive Manuel Vicente Vivo @manuelvicnt

Upload: manuel-vicente-vivo

Post on 07-Jan-2017

203 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Go reactive - Manuel Vicente Vivo

Go Reactive

Manuel Vicente Vivo

@manuelvicnt

Page 2: Go reactive - Manuel Vicente Vivo

What is Reactive Programming?

Go Reactive @manuelvicnt

Programming paradigm based on

Propagation of changes

Processing data flows

 Can be used in a Functional style

Page 3: Go reactive - Manuel Vicente Vivo

Propagation of Changes

Page 4: Go reactive - Manuel Vicente Vivo

Processing Data Flows

Output of processing the different flows

Source A

Source B Source B Modified

Page 5: Go reactive - Manuel Vicente Vivo

FUNCTIONAL REACTIVE

LAMBDAS

CLOSURES

COMPOSABLE

PUSH

EVENTS

ASYNCHRONOUS

@manuelvicnt Go Reactive

Page 6: Go reactive - Manuel Vicente Vivo

Reactive Extensions

 C#: Rx.NET

 Java: RxJava

 JavaScript: RxJS

Scala: RxScala

 Swift: RxSwift

 C++: RxCpp

 Ruby: Rx.rb

Python: RxPY

Groovy: RxGroovy

Kotlin: RxKotlin

Android: RxAndroid

iOS: RxCocoa

Go Reactive @manuelvicnt

Page 7: Go reactive - Manuel Vicente Vivo

RxJava http://github.com/Netflix/RxJava

“ A library for COMPOSING ASYNCHRONOUS and event-based

programs using OBSERVABLE SEQUENCES for the Java VM”

Go Reactive @manuelvicnt

Page 8: Go reactive - Manuel Vicente Vivo

Components

Go Reactive @manuelvicnt

 Observables: Emit Items

Subscribers: Consume Items

Common Methods: onNext

onCompleted

onError

Page 9: Go reactive - Manuel Vicente Vivo

Subscribers

Go Reactive @manuelvicnt

 Consume items

Page 10: Go reactive - Manuel Vicente Vivo

Observables

Go Reactive @manuelvicnt

Emit items

Page 11: Go reactive - Manuel Vicente Vivo

Subjects

Go Reactive @manuelvicnt

 Are both an Observable and a Subscriber

Page 12: Go reactive - Manuel Vicente Vivo

Operators http://rxmarbles.com

Go Reactive @manuelvicnt

Transformers map, flatMap

Filters filter, take, skip

Conditions takeWhile

Combination concat, zip

Aggregate count, toList

Page 13: Go reactive - Manuel Vicente Vivo

Go Reactive @manuelvicnt

Observable

Observable

Map Operator Observable

Zip Operator

Observable seen by the Subscriber

Page 14: Go reactive - Manuel Vicente Vivo

Backpressure

Go Reactive @manuelvicnt

The Observable is too fast for Subscribers

 Can happen anywhere in the chain

Operators: Throttle

Debounce

Page 15: Go reactive - Manuel Vicente Vivo

Testing Observables

Go Reactive @manuelvicnt

Create special cases

Observable.error()

Observable.empty()

Observable.never()

 Use TestSubscriber

Page 16: Go reactive - Manuel Vicente Vivo

Live Coding https://github.com/manuelvicnt/RxJava-android-structure

Fragments Subscribers

View Models Subjects

Registration API Service Observable

UserData Request Manager

Observable

Login API Service Observable

Account API Service Observable

Games API Service Observable

Authentication Request Manager

Observable

Retrofit Registration

Retrofit Login

Retrofit Account

Retrofit Games

Page 17: Go reactive - Manuel Vicente Vivo

Go Reactive @manuelvicnt

1. Registration Retrofit returns

Observable

2. Registration API Service propagates the

Observable

3. User Auth RM concatenates Login Request

4. User Auth RM gets the Login Observable

5. Subscribers will get this when subscribing to Registration,

Registration & Login request will be made and the result will be a

Login Response

Page 18: Go reactive - Manuel Vicente Vivo

Go Reactive @manuelvicnt

1.1 Account Data from Account API Service

Observable

3. Subscriber will get the result

when both requests come

2. Zip Operator in UserData RM Observable

1.2 Games Data from Games API Service

Observable