Skip to content

Commit

Permalink
Add JS template
Browse files Browse the repository at this point in the history
  • Loading branch information
Janiczek committed Nov 30, 2017
1 parent 2b9424b commit f3db2f2
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
81 changes: 81 additions & 0 deletions NodeTemplate.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
port module Year201X.DayXX exposing (..)

import Json.Decode


port elmAsks : String -> Cmd msg


port jsAnswers : (String -> msg) -> Sub msg


main : Program Never Model Msg
main =
Platform.program
{ init = init1
, update = update1

-- { init = init2
-- , update = update2
, subscriptions = subscriptions
}


type alias Model =
Int


type Msg
= JsAnswers String


init1 : ( Model, Cmd Msg )
init1 =
( initModel1, elmAsks (makeString initModel.id initModel.counter) )


initModel1 : Model
initModel1 =
0


init2 : ( Model, Cmd Msg )
init2 =
( initModel2, elmAsks (makeString initModel.id initModel.counter) )


initModel2 : Model
initModel2 =
0


update1 : Msg -> Model -> ( Model, Cmd Msg )
update1 msg model =
case msg of
JsAnswers hash ->
( model, Cmd.none )


toInt : String -> Int
toInt string =
string
|> String.toInt
|> Result.mapError (\_ -> Debug.crash "Wrong input!")
|> Result.withDefault 0


update2 : Msg -> Model -> ( Model, Cmd Msg )
update2 msg model =
case msg of
JsAnswers hash ->
( model, Cmd.none )


subscriptions : Model -> Sub Msg
subscriptions model =
jsAnswers JsAnswers


prepareForPort : String -> String
prepareForPort string =
string
4 changes: 4 additions & 0 deletions NodeTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const someDependency = require('some-dependency');
const Elm = require('../js/201X-XX.js');
const app = Elm.Year201X.DayXX.worker();
app.ports.elmAsks.subscribe(data => app.ports.jsAnswers.send(someDependency(data)));
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Dependencies: `elm-make`, `node`, [`entr`](http://entrproject.org/)

`./watch 2016 01` for autorun when developing ... or just once: `./run 2016 01`

For puzzles that need Node interop:

`./node_run 2016 01`

0 comments on commit f3db2f2

Please sign in to comment.