+ All Categories
Home > Mobile > Petr Šíma: Principy funkcionálně reaktivního programovaní na mobilních platformách

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

Date post: 16-Feb-2017
Category:
Upload: mdevtalk
View: 882 times
Download: 2 times
Share this document with a friend
33
Transcript
Page 1: Petr Šíma: Principy funkcionálně reaktivního programovaní na mobilních platformách
Page 2: Petr Šíma: Principy funkcionálně reaktivního programovaní na mobilních platformách

PETR SIMASenior iOS Developer, Ackee

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

Functional reactive programming

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

It's functional.

It's reactive.

You want to start using it today.

Functional reactive programming

4

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

1.5 years of experience with FRP

both iOS and Android

more to come at future mDevTalks

FRP at Ackee

5

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

for-loops

mutable state

"Push-based"

Imperative programming

6

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

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

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

= 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

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

Demo

9

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

composable, reusable

unidirectional dataflow

easy to reason about code

More buzzwords

ab

ab

10

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

composable, reusable

unidirectional dataflow

easy to reason about code

More buzzwords

Input --->

---> Output

11

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

composable, reusable

unidirectional dataflow

easy to reason about code

More buzzwords

12

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

composable, reusable

unidirectional dataflow

easy to reason about code

More buzzwords

Input --->

---> Output

13

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

composable, reusable

unidirectional dataflow

easy to reason about code

More buzzwords

Input --->

---> Output

14

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

Railway oriented programming

Error handling

15

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

Reactive code consists of elementary operations.

Don't be "too dry".

DRY principle?

16

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

Android

RxJava

Where to start?

iOS

RxSwift

Reactive Cocoa

17

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

18

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

19

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

Android

RxJava

Where to start?

iOS

RxSwift

Reactive Cocoa

Windows Phone

Rx.NET

20

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

Android

RxJava

Where to start?

iOS

RxSwift

Reactive Cocoa

Windows Phone

Rx.NET (RxExtensions)

21

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

Architecture of a reactive application

...

...ab

ab

22

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

Architecture of a reactive application

Massive View Controller

MVP MVVM

23

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

Architecture of a reactive application

MVC Model View Presenter

MVVM

24

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

Architecture of a reactive application

MVC MVP Model View ViewModel

25

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

Demo

26

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

RxSwift, RxJava, ...

Observable

Hot and cold signals

Reactive Cocoa

Signal

SignalProducer

27

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

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

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

Signals are hot.

SignalProducers are cold.

SignalProducer.start() creates a Signal.

Hot and cold signals

29

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

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

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

Actions, Schedulers, ...

31

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

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

Documentation

https://github.com/ReactiveX

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

Documentation

32

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

WWW.MDEVTALK.CZ

mdevtalk


Recommended