-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
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,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 |
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,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))); |
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 |
---|---|---|
@@ -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` |