Petr Šíma: Principy funkcionálně reaktivního programovaní na mobilních platformách

Post on 16-Feb-2017

882 views 2 download

transcript

PETR SIMASenior iOS Developer, Ackee

Functional reactive programming

It's functional.

It's reactive.

You want to start using it today.

Functional reactive programming

4

1.5 years of experience with FRP

both iOS and Android

more to come at future mDevTalks

FRP at Ackee

5

for-loops

mutable state

"Push-based"

Imperative programming

6

map, reduce, filter, flatMap

If a pure function is called with the same arguments, the same result will be returned.

declarative, "Pull-based", eliminates side effects, avoids

changing-state and mutable data

Functional programming

7

= reactive programming (asynchronous dataflow programming)

using the building blocks of functional programming (e.g. map, reduce, filter)

If a pure function is called with the same arguments, the same

result will be returned.

implicit parameter - time

FRP

8

Demo

9

composable, reusable

unidirectional dataflow

easy to reason about code

More buzzwords

ab

ab

10

composable, reusable

unidirectional dataflow

easy to reason about code

More buzzwords

Input --->

---> Output

11

composable, reusable

unidirectional dataflow

easy to reason about code

More buzzwords

12

composable, reusable

unidirectional dataflow

easy to reason about code

More buzzwords

Input --->

---> Output

13

composable, reusable

unidirectional dataflow

easy to reason about code

More buzzwords

Input --->

---> Output

14

Railway oriented programming

Error handling

15

Reactive code consists of elementary operations.

Don't be "too dry".

DRY principle?

16

Android

RxJava

Where to start?

iOS

RxSwift

Reactive Cocoa

17

18

19

Android

RxJava

Where to start?

iOS

RxSwift

Reactive Cocoa

Windows Phone

Rx.NET

20

Android

RxJava

Where to start?

iOS

RxSwift

Reactive Cocoa

Windows Phone

Rx.NET (RxExtensions)

21

Architecture of a reactive application

...

...ab

ab

22

Architecture of a reactive application

Massive View Controller

MVP MVVM

23

Architecture of a reactive application

MVC Model View Presenter

MVVM

24

Architecture of a reactive application

MVC MVP Model View ViewModel

25

Demo

26

RxSwift, RxJava, ...

Observable

Hot and cold signals

Reactive Cocoa

Signal

SignalProducer

27

A hot signal is active regardless of observers. "Signals are streams that are already in progress, e.g. notifications, user input, etc."

A cold signal starts work when subscribed to. "Cold signals represent operations or tasks, e.g. network requests."

Cold signals are lazy.

Hot and cold signals

28

Signals are hot.

SignalProducers are cold.

SignalProducer.start() creates a Signal.

Hot and cold signals

29

a mechanism for memory management and cancellation

disposable.dispose() interrupts a signal

usually don't have to be used directly in Reactive Cocoa

Disposables

30

Actions, Schedulers, ...

31

https://github.com/ReactiveCocoa/ReactiveCocoa/tree/master/

Documentation

https://github.com/ReactiveX

http://neilpa.me/rac-marbles/

Documentation

32

WWW.MDEVTALK.CZ

mdevtalk