21
RxJS vs RxJava Intro

RxJS vs RxJava: Intro

Embed Size (px)

Citation preview

Page 1: RxJS vs RxJava: Intro

RxJS vs RxJavaIntro

Page 2: RxJS vs RxJava: Intro

Agenda

• Reactive Programming• Functional Reactive Programming• RxJS• RxJava

Page 3: RxJS vs RxJava: Intro

Reactive Programming

Page 4: RxJS vs RxJava: Intro

Reactive Programming

• In imperative programming languages expressions are evaluated “in place”:

a = 10;b = 20;c = a + b; // c = 30a = 40; // c = 30

Page 5: RxJS vs RxJava: Intro

Reactive Programming

• In reactive programming languages changes in the data flow may trigger changes to multiple variables:

a = 10;b = 20;c = a + b; // c = 30a = 40; // c = 60

Page 6: RxJS vs RxJava: Intro

Reactive Programming

• Reactive programming may also refer to the interaction between different systems or components in a system

• In that regard the libraries we will be discussing do not serve as a replacement of message brokers (such as RabbitMQ, Kafka, MSMQ and a number of others)

Page 7: RxJS vs RxJava: Intro

Reactive Programming

• In this clash we would refer to the “programming language” - inferred meaning behind reactive programming

Page 8: RxJS vs RxJava: Intro

Reactive Programming

• The Reactive Manifesto:

Page 9: RxJS vs RxJava: Intro

Functional Reactive Programming

Page 10: RxJS vs RxJava: Intro

Functional Reactive Programming

• A more common subset is functional reactive programming (FRP) that makes use of streams and stream operations for anything (input, changes in variables and many more) in order to achieve reactiveness

• Connal Elliot – ground-breaking paper @Conference on Functional Programming, 1997

Page 11: RxJS vs RxJava: Intro

Functional Reactive Programming

•Reactive Programming = Programming with Asynchronous Data Streams

•Functional Reactive Programming (FRP) = programming paradigm for reactive programming that uses the building blocks of functional programming (e.g. map, reduce, filter). FRP has been used for programming graphical user interfaces (GUIs), robotics, and music, aiming to simplify these problems by explicitly modeling time. [Wikipedia]

Page 12: RxJS vs RxJava: Intro

Functional Reactive Programming

•Reactive Programming = Programming with Asynchronous Data Streams

•Functional Reactive Programming (FRP) = programming paradigm for reactive programming that uses the building blocks of functional programming (e.g. map, reduce and filter)

Page 13: RxJS vs RxJava: Intro

Functional Reactive Programming

• FRP has been used in:

– responsive graphical user interfaces (GUIs)

– robotics

– the music industry

Page 14: RxJS vs RxJava: Intro

Functional Reactive Programming

• RxJava and RxJS implement the functional reactive programming paradigm in terms of libraries for the Java and JavaScript programming languages correspondingly …

• Derived on the basis of Microsoft’s Reactive Extensions (Rx) library for .NET

Page 15: RxJS vs RxJava: Intro

Functional Reactive Programming

Microsoft® open source polyglot project ReactiveX (Reactive Extensions) [http://reactivex.io]: Rx = Observables + LINQ + Schedulers :)• Supported Languages – Java: RxJava, JavaScript: RxJS, C#:

Rx.NET, C#(Unity): UniRx, Scala: RxScala, Clojure: RxClojure, C++: RxCpp, Ruby: Rx.rb, Python: RxPY, Groovy: RxGroovy, JRuby: RxJRuby, Kotlin: RxKotlin, Swift: RxSwift

• ReactiveX for platforms and frameworks: RxNetty, RxAndroid, RxCocoa

Page 16: RxJS vs RxJava: Intro

Functional Reactive Programming

• Rx has an implicit contract that must be followed:

event source

OnNext(item) OnNext(item) OnNext(item)

OnCompleted()

OnError(Exception)

Page 17: RxJS vs RxJava: Intro

RxJS

Page 18: RxJS vs RxJava: Intro

RxJsRx.Observable.from(["Reactive", "Extensions", "Java“])

.take(2) .map(function(s) { s + " : on " + new Date()})

.subscribe(function(s) {console.log(s)});

Result: Reactive : on Wed Jun 17 21:54:02 GMT+02:00 2015

Extensions : on Wed Jun 17 21:54:02 GMT+02:00 2015

Page 19: RxJS vs RxJava: Intro

RxJava

Page 20: RxJS vs RxJava: Intro

RxJava

Observable.from(new String[] {"Reactive", "Extensions", "Java"})

.take(2) .map(s -> s + " : on " + new Date()) .subscribe(s -> System.out.println(s));

Result: Reactive : on Wed Jun 17 21:54:02 GMT+02:00 2015

Extensions : on Wed Jun 17 21:54:02 GMT+02:00 2015

Page 21: RxJS vs RxJava: Intro

RxJava

• Lambdas and streams introduced in Java 8 make the FRP style of programming in Java easier to accomplish

• There is a proposal for introducing a reactive streaming API as part of the core libraries in JDK 9