Five Unbelievable Secrets of Reactive Programming the Experts Don't Want You to Know!

06609d73ad2165c4aafcf65a1ddb9563?s=47 Greg Heo
February 24, 2017

Five Unbelievable Secrets of Reactive Programming the Experts Don't Want You to Know!

Totally non-clickbaity article about lessons learned from reactive programming. Presented at Playgrounds, Melbourne, February 24, 2917.

06609d73ad2165c4aafcf65a1ddb9563?s=128

Greg Heo

February 24, 2017
Tweet

Transcript

  1. @gregheo

  2. FIVE ✋ Of Reactive Programming Unbelievable! Secrets The Experts Don’t

    Want YOU To Know!
  3. None
  4. $ You already know it!

  5. Data flows Propagation of change

  6. ' Sequences!

  7. A type that provides sequential, iterated access to its elements.

    Sequence
  8. A type that provides sequential, iterated access to its elements.

    Sequence
  9. A type that provides sequential, iterated access to its elements.

    Sequence
  10. Sequence indexable single direction unbounded?

  11. None
  12. View
 controller (x, y) Game
 controller Square View Move index

  13. SEQUENCES SEQUENCES EVERYWHERE

  14. ) Small pieces of logic

  15. View
 controller (x, y)

  16. .map({ (point: NSPoint) -> Int in for (i, squareView) in

    squareViews.enumerated() { if squareView.frame.contains(point) { return i } } }) vc.rx_mouseClicks an observable (aka a sequence) 0 1 2 3 4 5 6 7 8
  17. View
 controller (x, y) Game
 controller Square index Square index

  18. Game
 controller View
 controller (x, y) Square index

  19. None
  20. * Declarative style

  21. View
 controller (x, y) Game
 controller Square View
 controller Result

    index View Move
  22. gameController.resultObservable .subscribe(onNext: { moveResult in switch moveResult { case .win(let

    winner): let alert = NSAlert()
 // Show alert for winner case .draw: let alert = NSAlert()
 // Show alert for draw case .success(nextPlayer: player):
 // ... case .invalid(nextPlayer: player): // ... } })
  23. gameController.moveObservable .subscribe(onNext: { singleMove in squareViews[singleMove.square].squareState = singleMove.player }) 0

    1 2 3 4 5 6 7 8
  24. View
 controller (x, y) Game
 controller Square View
 controller Result

    index View Move
  25. + Testable code

  26. None
  27. Game
 controller Square index (Int) Result

  28. Game
 controller let moves: [Int] = [1, 3, 52, 4]

    [.success(nextPlayer: .nought), .success(nextPlayer: .cross), .success(nextPlayer: .nought)] .invalid(nextPlayer: .cross),
  29. [.success(nextPlayer: .nought), .success(nextPlayer: .cross), .success(nextPlayer: .nought)] .invalid(nextPlayer: .cross), XCTAssertEqual( ,

    expected)
  30. None
  31. Data flows Propagation of change

  32. 1. You already know it 2. Sequences everywhere 3. Small

    pieces of logic 4. Declarative style 5. Testable code
  33. None
  34. so reactive very sequence much declarative such testable wow

  35. so reactive very sequence much declarative such testable wow

  36. feedback gregheo.com