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

From Ember to Elm

From Ember to Elm

An introduction to Elm for Ember developers.

Avatar for Kirill Korolyov

Kirill Korolyov

October 20, 2016
Tweet

Other Decks in Programming

Transcript

  1. from : a friendly introduction to Elm → for Ember

    developers elm by Kirill Korolyov
  2. Why? better API for the web batteries included ember-cli component

    model scales rich addon ecosystem well-maintained just works! easy to start
  3. BUT

  4. Javascript npm null == this keyword not everything is an

    expression weak typing “JavaScript fatigue” slow installation times undefined is not a function (deprecated) thousands of tiny packages dynamic typing writing your own framework inheritance monkey patching jQuery runtime exceptions Native APIs maintainability TC39 backwards compatible forever undefined stringly typed makes me cry at night
  5. What is Elm? typed, pure functional programming language for the

    browser (might sounds boring, but please stick around, there’ll be rainbows)
  6. A functional programming language is one that supports and encourages

    programming without side-effects. — Kris Jenkins http://blog.jenkster.com/2015/12/what-is-functional-programming.html
  7. What is an (non-side) effect? • rendering and changing HTML

    • making a HTTP request • getting current time • generating random number • listening to DOM events • more generally, any interaction with the outside world — including the web browser
  8. What is a side effect? An effect which is not

    an explicit input or output to a function Also, mutable state
  9. A pure function always produces the same value when given

    the same arguments.
 It can’t “do” anything.
  10. Why? • optimization • memoization • referential transparency • rendering

    performance • testing • easy understand and predict the behavior • time-traveling debugger • separation of concerns (what vs how)
  11. Elm doesn’t care about where you place your code. There’s

    no magic either. Regardless, it enables you to write
 well-architected code.
  12. Elm is not so opinionated • no defined file layout

    • no Ember Data alternative (but you might not need it) • no out-of-the-box routing solution (Elmers don’t even call it “routing”) (compared to Ember)
  13. Elm is opinionated about • transpiler • type system •

    semantic versioning • core library • DOM rendering elm-lang/core elm-lang/html (compared to pure JavaScript) the Elm architecture
  14. The Elm Architecture “it will happen to you whether you

    know about it or not” — Evan Czaplicki, “An Introduction to Elm”
  15. View a way to render your state as HTML Ember

    analogy: template, helper and parts of component
  16. Spot any problems? • is it clear what inputs to

    the template or component are? • what happens if user is undefined, has no name or is a number?
  17. Model the state of your app Ember analogy: internal state

    of store, all services and components
 not to be confused with Ember Data models

  18. Recap Elm makes you write well-architected and maintainable code The

    type system and the compiler do amazing job at error detection Programming without mutations and side-effects Explicit state management In fact, we have only scratched the surface here!