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

The ELM Architecture

The ELM Architecture

Eeb061c8b2816b771920da1b3e7904a3?s=128

Swift India

May 25, 2019
Tweet

Transcript

  1. THE ELM ARCHITECTURE Damodar Shenoy

  2. LET’S TAKE A STEP BACK… IMPERATIVE APPROACH ▸ Telling program

    how to solve the problem ▸ Step by step procedures ▸ Series of statements ▸ Use case driven ▸ Defines Object ▸ May have side effects ▸ Easy to debug stepwise ▸ C++, Java, Swift
  3. NOW LET’S LOOK AT… DECLARATIVE APPROACH ▸ Telling program what

    to do exactly ▸ Declare what the end result is ▸ Series of expressions ▸ Constraint driven ▸ Defines functions (first-class & higher order) ▸ Comparatively lesser side effects ▸ Same input —> same output ▸ Scala, Haskell, Lisp, Elm, Swift
  4. WHY IS SWIFT IN BOTH APPROACHES…? IN SWIFT ▸ Everything

    is a closure ▸ That means we do functional programming using closure
  5. COMING BACK TO THE TOPIC…? ELM ▸ is a programming

    language for web ▸ is completely based on declarative approach
  6. ELM LANGUAGE…

  7. HOW DOES ELM WORK? Elm Runtime / External Entities &

    Actions Update Virtual Views Model command / message updates model (ideally creates) updated model is passed to views Model: Record/Data Cmd Msg: Type update(cmd, model) -> (cmd) view(model) -> (view-msg)
  8. DEMO - COUNTDOWN TIMER

  9. ELM IN SWIFT… VIEW

  10. ELM IN SWIFT… ACTION

  11. ELM IN SWIFT… UPDATE

  12. ELM IN SWIFT… APP STATE:

  13. ELM IN SWIFT… ELM RUNTIME (DRIVER)

  14. DEMO itsCodingTime()

  15. WHY ELM ? ADVANTAGES: ▸ Consistent state management ▸ No

    runtime exceptions ▸ Declarative ▸ Immutable Models ▸ All other pros of a functional program
  16. WHY NOT ELM ? ▸ If you need to change

    a value deep inside a nested data structure, you can't simply read the value and mutate it, as you could in imperative approach ▸ If you are from OOP background: ▸ feels very restrictive ▸ for loops replaced by higher order functions DISADVANTAGES:
  17. IF I AM NOT WORKING WITH THIS THEN… ? ▸

    Experience of working in an alien for a little bit is also fruitful ▸ Learn to deal with purity, immutability (functional) ▸ Constraints will push creativity ▸ Strategies in other approaches ▸ Functional Programming is different WHY LEARN?
  18. MY PRESENTATION IS… BASED UPON ▸ The Complete Bundle (Swift):

    ▸ https://www.objc.io/books/bundles/complete- collection/ ▸ https://github.com/objcio/app-architecture ▸ https://github.com/chriseidhof/tea-in-swift ▸ The ELM Language: https://guide.elm-lang.org/
  19. OTHER WORKS ON… DECLARATIVE APPROACH IN SWIFT ▸ CocoaWithLove -

    CwlViews: https:// www.cocoawithlove.com/blog/introducing-cwlviews.html ▸ React and Elm Inspired framework in Swift - https:// gist.github.com/inamiy/ bd257c60e670de8a144b1f97a07bacec ▸ The SAM Pattern ▸ http://sam.js.org/ (Original javascript library) ▸ https://github.com/fe9lix/SAM-Swift (Swift framework)
  20. REFERENCES… VIDEOS ▸ Yasuhiro Inami: Elm in Swift talk -

    https:// www.youtube.com/watch?v=7TJBbUFpsvE ▸ Sam Ritchie - Using the Elm Architecture in Swift - https:// www.youtube.com/watch?v=iiXAWcNkIbw ▸ A Peek into Elm Architecture - https://www.infoq.com/ presentations/elm-architecture ▸ An Introduction to Elm's Features and Architecture - https://www.youtube.com/watch?v=vgsckgtVdoQ
  21. CONNECT WITH ME… ▸ Twitter @itsdamslife ▸ Github https://github.com/itsdamslife ▸

    Today’s demo source code ▸ https://github.com/itsdamslife/ELMTimer
  22. THANK YOU… thankYou()