@JoGrenat #elmlang
2003
2008-2009
2014
Virtual DOM
One-way data flow
const numbers = [1, 2, 3, 4, 5];
let squares = [];
for (const i = 0, length = numbers.length; i < length; i++) {
squares.push(numbers[i] * numbers[i]);
}
const numbers = [1, 2, 3, 4, 5];
const squares = numbers.map(n => n * n);
ES5
Typage
Immutabilité
Programmation Fonctionnelle
One-way data flow
Components
Virtual DOM
main : Program Never Model Msg
main =
program { view = view, init = init, update = update, subscriptions = subscriptions }
-- ...
subscriptions : Model -> Sub Msg
subscriptions model =
usernameFromLS ReceivedUsernameFromLS
port registerUsernameToLS : String -> Cmd msg
port usernameFromLS : (String -> msg) -> Sub msg
const app = Elm.Main.embed(root);
app.ports.registerUsernameToLS.subscribe(username => {
window.localStorage.setItem('username', username)
});
if (window.localStorage.getItem('username') !== null) {
const username = window.localStorage.getItem('username');
app.ports.usernameFromLS.send(username);
}
module Tests exposing (..)
import Test exposing (..)
import Expect
import App exposing (update, Msg(CoinFlipped), CoinState(Heads))
all : Test
all =
describe "A CoinFlipped should start a new game"
[ test <|
\() ->
Expect.equal (update (CoinFlipped Heads) NoGame) (Game Heads)
]