Last active
June 30, 2017 23:54
-
-
Save wende/4c1a74a20acc801e82caef421f97a1cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module GlobalCounter exposing (..) | |
type alias Model = Int | |
type Msg | |
= Increment | |
| Decrement | |
| Reset | |
| GetState Pid | |
main = | |
GenServer.singleton | |
{ init = init | |
, send = send | |
, update = update | |
} | |
send : msg -> | |
init : a -> Model | |
init = 0 | |
update : Pid -> Model -> Message -> (Model, Cmd) | |
handleCast self state msg = | |
case msg of | |
Increment -> | |
state + 1 ! [] | |
Decrement -> | |
state - 1 ! [] | |
Reset -> | |
0 ! [] | |
GetState from -> | |
state ! [ Process.send from state ] | |
This file contains hidden or 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
module GenServer exposing (genserver) | |
type alias GenServer a model msg = | |
{ send : a | |
, init : model | |
, update : Pid -> model -> msg -> (model, Cmd msg) | |
} | |
singleton : GenServer (Cmd a) model msg -> | |
regular : Genserver (Pid -> Cmd a) model msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment