-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Elm docs * Update elm.md
- Loading branch information
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
layout: layout.njk | ||
eleventyNavigation: | ||
key: languages-elm | ||
title: <img src="/assets/lang-icons/elm.svg" alt=""/> Elm | ||
order: 9 | ||
--- | ||
|
||
You can import [Elm](https://elm-lang.org/) files like any another Javascript files. | ||
|
||
The npm package `elm` needs to be manually installed beforehand. You'll also need a `elm.json` configuration file (run `yarn elm init -y` to get started and modify it if neccessary). | ||
|
||
{% sample null, "column" %} | ||
{% samplefile "index.html" %} | ||
|
||
```html | ||
<!DOCTYPE html> | ||
<div id="root"></div> | ||
<script src="index.js"></script> | ||
``` | ||
|
||
{% endsamplefile %} | ||
|
||
{% samplefile "index.js" %} | ||
|
||
```js | ||
import { Elm } from "./Main.elm"; | ||
|
||
Elm.Main.init({ node: document.getElementById("root") }); | ||
``` | ||
|
||
{% endsamplefile %} | ||
|
||
{% samplefile "Main.elm" %} | ||
|
||
```elm | ||
module Main exposing (..) | ||
|
||
import Browser | ||
import Html exposing (Html, button, div, text) | ||
import Html.Events exposing (onClick) | ||
|
||
main = | ||
Browser.sandbox { init = init, update = update, view = view } | ||
|
||
type alias Model = Int | ||
|
||
init : Model | ||
init = | ||
0 | ||
|
||
type Msg = Increment | Decrement | ||
|
||
update : Msg -> Model -> Model | ||
update msg model = | ||
case msg of | ||
Increment -> | ||
model + 1 | ||
|
||
Decrement -> | ||
model - 1 | ||
|
||
|
||
view : Model -> Html Msg | ||
view model = | ||
div [] | ||
[ button [ onClick Decrement ] [ text "-" ] | ||
, div [] [ text (String.fromInt model) ] | ||
, button [ onClick Increment ] [ text "+" ] | ||
] | ||
``` | ||
|
||
{% endsamplefile %} | ||
|
||
{% endsample %} | ||
|
||
## Time-travelling debuggger | ||
|
||
Elm's debug mode is automatically enabled when not building for production (it is disabled automatically with `parcel build`). You can set the environment variable `PARCEL_ELM_NO_DEBUG=1` to disable it even in development mode. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93b92af
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: