Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Functional Reactive Programming in Mobile Development

Functional Reactive Programming in Mobile Development

Rx Programming is a new pattern to handle asynchronous events and it is very useful in mobile development.

In 20 minutes of Mobile Day Vietnam 2016, the deck tried to provide the overview of the rx programming concept and some of its advantages in Android and iOS Development.

The last part of this presentation is a short demo excerpt from source code of product Amio by Dwarves Foundation.

Han Ngo

June 18, 2016
Tweet

More Decks by Han Ngo

Other Decks in Programming

Transcript

  1. Me • Han @ Dwarves Foundation • Software Engineer &

    Tech Entrepreneur • Initiate Golang Vietnam | 2014 • @nntruonghan Dwarves Foundation, 2016 2
  2. Dwarves Foundation • Startup Factory • Development Lab • Golang-based

    systems • Mobile focused with Rx Programming Dwarves Foundation, 2016 3
  3. Agenda • Rx Intro • Applied Rx: Android & iOS

    • Rx at Dwarves Foundation • Q&A Dwarves Foundation, 2016 4
  4. Why another pattern? • Pattern to handle asynchronous events •

    Build software in faster & more interesting way • Make programmer life easier Dwarves Foundation, 2016 5
  5. Rx Alamofire.request(.POST, "login", parameters: ["username": "max", "password": "insanity"]) .responseJSON(completionHandler: {

    (firedResponse) -> Void in Alamofire.request(.GET, "myUserInfo" + firedResponse.result.value) .responseJSON(completionHandler: { myUserInfoResponse in Alamofire.request(.GET, "friendList" + myUserInfoResponse.result.value) .responseJSON(completionHandler: { friendListResponse in Alamofire.request(.GET, "blockedUsers" + friendListResponse.result.value) .responseJSON(completionHandler: { }) }) }) Alamofire.request(.GET, "myUserAcccount" + firedResponse.result.value) .responseJSON(completionHandler: { }) }) Dwarves Foundation, 2016 6
  6. Rx Reactive programming is programming with asynchronous data streams •

    A stream is a sequence of ongoing events ordered in time. • Everything can be a stream: variables, user inputs, properties, caches, data structures ... Dwarves Foundation, 2016 7
  7. Stream (again) • onNext • onError • onCompleted Stream 1

    -> Stream 2 -> Stream ... -> Stream N Dwarves Foundation, 2016 10
  8. Imperative var a = 10; var b = a +

    1; a = 11; b = a + 1; Dwarves Foundation, 2016 12
  9. Declarative var a = 10; var b <= a +

    1; a = 20; Assert.AreEqual(21, b); Dwarves Foundation, 2016 13
  10. • The stream is the subject (or "observable") being observed

    • The "listening" to the stream is called subscribing • The functions we are defining are observers Dwarves Foundation, 2016 14
  11. Rx Extension in Android & iOS • Rx family •

    RxSwift / RxCocoa • RxJava / RxAndroid Dwarves Foundation, 2016 15
  12. Adoption • Thinking in Reactive • Forcing your brain to

    work in a different paradigm Dwarves Foundation, 2016 17
  13. Why Rx enables building apps in a declarative way •

    Bindings • Easy Integration • Less stateful Dwarves Foundation, 2016 18