Skip to content

Commit 5567938

Browse files
committed
Bump flake
1 parent 6f017ab commit 5567938

File tree

5 files changed

+49
-40
lines changed

5 files changed

+49
-40
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
21
name: Build and deploy
32

43
on:
54
push:
65
branches: main
6+
pull_request:
77

88
permissions:
99
contents: read
@@ -30,6 +30,7 @@ jobs:
3030
path: ./public
3131

3232
deploy:
33+
if: github.ref == 'refs/heads/main'
3334
runs-on: ubuntu-latest
3435

3536
environment:

cabal.project

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ flags: +template-haskell
99
source-repository-package
1010
type: git
1111
location: https://github.com/dmjio/miso
12-
branch: master
13-
12+
tag: 8c4b85e6e1279bec9b66859c54f25209701b8153

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

miso-websocket.cabal

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@ cabal-version: 3.0
22
name: miso-websocket
33
version: 0.1
44

5+
common warnings
6+
ghc-options:
7+
-funbox-strict-fields -O2 -ferror-spans -fspecialise-aggressively -Wall
8+
9+
common wasm
10+
if arch(wasm32)
11+
ghc-options:
12+
-no-hs-main -optl-mexec-model=reactor "-optl-Wl,--export=hs_start"
13+
cpp-options:
14+
-DWASM
15+
516
executable app
6-
hs-source-dirs: src
7-
main-is: Main.hs
8-
build-depends: base, aeson, miso, mtl
9-
default-language: GHC2021
10-
ghc-options: -Wall -no-hs-main -optl-mexec-model=reactor "-optl-Wl,--export=hs_start" -ddump-splices
11-
cpp-options: -DWASM
12-
default-extensions: CPP TemplateHaskell
13-
17+
import:
18+
wasm, warnings
19+
hs-source-dirs:
20+
src
21+
main-is:
22+
Main.hs
23+
build-depends:
24+
base, aeson, miso, mtl
25+
default-language:
26+
GHC2021
27+
default-extensions:
28+
CPP TemplateHaskell

src/Main.hs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1+
-----------------------------------------------------------------------------
12
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE DeriveGeneric #-}
3-
{-# LANGUAGE ExtendedDefaultRules #-}
4-
{-# LANGUAGE FlexibleInstances #-}
5-
{-# LANGUAGE MultiParamTypeClasses #-}
63
{-# LANGUAGE OverloadedStrings #-}
74
{-# LANGUAGE RecordWildCards #-}
8-
{-# LANGUAGE ScopedTypeVariables #-}
9-
{-# LANGUAGE TypeFamilies #-}
10-
5+
-----------------------------------------------------------------------------
116
module Main where
12-
7+
-----------------------------------------------------------------------------
138
import Control.Monad.State
149
import Data.Aeson
1510
import Data.Bool
1611
import GHC.Generics
17-
12+
-----------------------------------------------------------------------------
1813
import Miso
1914
import Miso.String (MisoString)
2015
import qualified Miso.String as S
21-
2216
import qualified Miso.Style as CSS
23-
17+
-----------------------------------------------------------------------------
2418
#if WASM
2519
foreign export javascript "hs_start" main :: IO ()
2620
#endif
27-
21+
-----------------------------------------------------------------------------
2822
main :: IO ()
29-
main = run (startComponent app)
30-
31-
app :: Component Model Action
23+
main = run (startApp app)
24+
-----------------------------------------------------------------------------
25+
app :: App Model Action
3226
app = (component emptyModel updateModel appView)
3327
{ events = defaultEvents <> keyboardEvents
3428
, subs =
@@ -37,38 +31,37 @@ app = (component emptyModel updateModel appView)
3731
} where
3832
url = URL "wss://echo.websocket.org"
3933
protocols = Protocols []
40-
41-
34+
-----------------------------------------------------------------------------
4235
emptyModel :: Model
4336
emptyModel = Model (Message "") mempty
44-
45-
updateModel :: Action -> Effect Model Action
37+
-----------------------------------------------------------------------------
38+
updateModel :: Action -> Transition Model Action
4639
updateModel (HandleWebSocket (WebSocketMessage (Message m))) =
4740
modify $ \model -> model { received = m }
4841
updateModel (SendMessage msg) =
4942
io_ (send msg)
5043
updateModel (UpdateMessage m) = do
5144
modify $ \model -> model { msg = Message m }
5245
updateModel _ = pure ()
53-
46+
-----------------------------------------------------------------------------
5447
instance ToJSON Message
5548
instance FromJSON Message
56-
49+
-----------------------------------------------------------------------------
5750
newtype Message = Message MisoString
5851
deriving (Eq, Show, Generic)
59-
52+
-----------------------------------------------------------------------------
6053
data Action
6154
= HandleWebSocket (WebSocket Message)
6255
| SendMessage Message
6356
| UpdateMessage MisoString
6457
| Id
65-
58+
-----------------------------------------------------------------------------
6659
data Model = Model
6760
{ msg :: Message
6861
, received :: MisoString
6962
} deriving (Show, Eq)
70-
71-
appView :: Model -> View Action
63+
-----------------------------------------------------------------------------
64+
appView :: Model -> View Model Action
7265
appView Model{..} =
7366
div_
7467
[ CSS.style_ [ CSS.textAlign "center" ] ]
@@ -91,6 +84,7 @@ appView Model{..} =
9184
[text (S.pack "Send to echo server")]
9285
, div_ [] [p_ [] [text received | not . S.null $ received]]
9386
]
94-
87+
-----------------------------------------------------------------------------
9588
onEnter :: Action -> Attribute Action
9689
onEnter action = onKeyDown $ bool Id action . (== KeyCode 13)
90+
-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)