application as data flow - lscc talks #5
DESCRIPTION
Introduction to treating applications as flows of pure data and how to implement this in practise with functional reactive programming.TRANSCRIPT
Building watertight business logic
Application asdata flow
@tehmou
Functional Reactive Programming» Also known as FRP or Rx
» Streams over variables
» Push over pull
» Pure functions over stateful objects
08/21/14
Stream is a pub/subWith no events – just data
08/21/14
Observable Observer
.. with some operations in between.. that can change the type of data
08/21/14
Observable 1
Observer
filter
combine latest
Observable 2
Example:Github searchSearching repositories by name and minimum number of watchers08/21/14
The API» https://api.github.com/search/repositories?q=xxx
» Open API with an aggressive rate limit
» Should not be hit too often
» JSON response with details about the repo
08/21/14
Search input» Search only when more than two characters present
» Do not search until the text has been unchanged for 500ms
» Add ability to filter by a minimum watcher count
708/21/14 Futurice
808/21/14 Futurice
Text input Data flowarchitecture
UI Events
908/21/14 Futurice
Text input
convert eventsto strings
Data flowarchitecture
String
1008/21/14 Futurice
Text input
filter/throttle
convert eventsto strings
Data flowarchitecture
String(some are discarded)
1108/21/14 Futurice
Text input
filter/throttle
API APInetwork
convert eventsto strings
Data flowarchitecture
Array of JSON
1208/21/14 Futurice
Text input
Minimum watchersfilter/throttle
API API
combine/filter
network
convert eventsto strings
Data flowarchitecture
Filtered Array of JSON
1308/21/14 Futurice
Text input
Minimum watchersfilter/throttle
API API
combine/filter
render
network
convert eventsto strings
Data flowarchitecture
Implementation in Bacon.js» http://jsfiddle.net/tehmou/2gxao3j4/5/
1408/21/14 Futurice
Other input sources of an app» User navigates within the app
» Friends list is refreshed in the background
» Message delivery fails
» Application is suspended
» FarmVille request arrives
Values/events can go into the system only from the designated entry points.
that’s a period
More complexapplications
NetworkObservable
Disk store
parse cache
get additional information
Network again
View logic
View
Why You Should do It?» Cleaner code
» Makes you understand how your application really works
» .. or how it is supposed to work, at least
» Bugs are easier to track
Resources» My technical blog post for RxJava:
http://blog.futurice.com/top-7-tips-for-rxjava-on-android
» RxMarbles for understanding stream operations: http://rxmarbles.com/
» Original Rx: http://msdn.microsoft.com/en-gb/data/gg577609.aspx
» For JavaScript: http://baconjs.github.io/ or https://github.com/Reactive-Extensions/RxJS
Timo TuominenSoftware [email protected]@gmail.com+44 7404 948860
Contact