push 3 sub projects

This commit is contained in:
2025-06-24 17:31:43 +01:00
parent d421a5b009
commit 83861987cf
4 changed files with 127 additions and 0 deletions

34
server/.gitignore vendored Normal file
View File

@@ -0,0 +1,34 @@
# haskell
.stack-work/
dist-newstyle/
cabal.project.local
.ghc.environment.*
dist
*.o
*.hi
*.jsexe
# nix
result*
# emacs
*~
# darwin
.DS_Store
# misc
TAGS
tags
.direnv
# js
package-lock.json
node_modules/
coverage/
# typescript
*.js
# haddocks
haddocks/

62
server/Main.hs Normal file
View File

@@ -0,0 +1,62 @@
----------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE CPP #-}
----------------------------------------------------------------------------
module Main where
----------------------------------------------------------------------------
import Miso
import Miso.String
import Miso.Lens
----------------------------------------------------------------------------
-- | Component model state
newtype Model = Model
{ _counter :: Int
} deriving (Show, Eq)
----------------------------------------------------------------------------
counter :: Lens Model Int
counter = lens _counter $ \record field -> record { _counter = field }
----------------------------------------------------------------------------
-- | Sum type for Component events
data Action
= AddOne
| SubtractOne
| SayHelloWorld
deriving (Show, Eq)
----------------------------------------------------------------------------
-- | Entry point for a miso application
main :: IO ()
main = run (startComponent component)
----------------------------------------------------------------------------
-- | WASM export, required when compiling w/ the WASM backend.
#ifdef WASM
foreign export javascript "hs_start" main :: IO ()
#endif
----------------------------------------------------------------------------
-- | `defaultComponent` takes as arguments the initial model, update function, view function
component :: Component name Model Action
component = defaultComponent emptyModel updateModel viewModel
----------------------------------------------------------------------------
-- | Empty application state
emptyModel :: Model
emptyModel = Model 0
----------------------------------------------------------------------------
-- | Updates model, optionally introduces side effects
updateModel :: Action -> Effect Model Action
updateModel = \case
AddOne -> counter += 1
SubtractOne -> counter -= 1
SayHelloWorld -> io_ $ do
consoleLog "Hello World"
alert "Hello World"
----------------------------------------------------------------------------
-- | Constructs a virtual DOM from a model
viewModel :: Model -> View Action
viewModel x = div_ []
[ button_ [ onClick AddOne ] [ text "+" ]
, text $ ms (x ^. counter)
, button_ [ onClick SubtractOne ] [ text "-" ]
, button_ [ onClick SayHelloWorld ] [ text "Alert Hello World!" ]
]
----------------------------------------------------------------------------

24
server/app.cabal Normal file
View File

@@ -0,0 +1,24 @@
cabal-version: 2.2
name: app
version: 0.1.0.0
synopsis: Sample miso app
category: Web
common wasm
if arch(wasm32)
ghc-options:
-no-hs-main
-optl-mexec-model=reactor
"-optl-Wl,--export=hs_start"
cpp-options:
-DWASM
executable app
import:
wasm
main-is:
Main.hs
build-depends:
base, miso
default-language:
Haskell2010

7
server/cabal.project Normal file
View File

@@ -0,0 +1,7 @@
packages:
.
source-repository-package
type: git
location: https://github.com/dmjio/miso
branch: master