Code Monkey home page Code Monkey logo

start-app's Introduction

Using Elm is easier than ever

Getting started with Elm is now easier than ever with the StartApp package.

With the Elm Architecture, it has never been easier to write modular front-end code that is shockingly fast and easy to test, refactor, and debug. The StartApp package drastically lowers the barrier to entry, setting everything up so you can focus entirely on writing your app.

Example

The following chunk of code sets up a simple counter that you can increment and decrement. Notice that you focus entirely on setting up model, view, and update. That is it, no distractions!

import Html exposing (div, button, text)
import Html.Events exposing (onClick)
import StartApp.Simple as StartApp


main =
  StartApp.start { model = model, view = view, update = update }


model = 0


view address model =
  div []
    [ button [ onClick address Decrement ] [ text "-" ]
    , div [] [ text (toString model) ]
    , button [ onClick address Increment ] [ text "+" ]
    ]


type Action = Increment | Decrement


update action model =
  case action of
    Increment -> model + 1
    Decrement -> model - 1

Paste the code into Elm's online editor to see it in action. From there, install Elm on your machine and start working through the Elm Architecture tutorial which starts with this counter example and gradually works up to programs with HTTP and animation.

Notice that the update and view functions are totally separate. This is great for architecture, but it also makes testing way easier. Your application logic is entirely isolated, so you can make sure it works correctly without worrying about the DOM.

So this is a super simple program, but the core concepts here can grow into great code bases if you follow the Elm Architecture.

Further Learning

Check out the full documentation for this library here.

For more guidelines and examples of making apps in Elm, check out the following resources:

  • Language Docs — tons of learning resources that go from syntax to language features to design guidelines.
  • The Elm Architecture — simple examples demonstrating how our basic counter app can scale to huge applications that are easy to test, maintain, and refactor.
  • elm-todomvc — a typical TodoMVC program (live) built on the Elm Architecture. You will see the model, update, view pattern but for a more realistic application than a counter.
  • dreamwriter — a writing app built in Elm that again uses the Elm Architecture. The creator has never had a runtime exception in his Elm code. Unlike JavaScript, Elm is designed for reliability that scales to any size.

start-app's People

Contributors

process-bot avatar shiftkey avatar echatav avatar gcapizzi avatar jessitron avatar inchingforward avatar thomasweiser avatar hoosieree avatar jvoigtlaender avatar zigomir avatar

Watchers

Donghee Kim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.