Skip to content

Commit f63bf69

Browse files
authored
Bump flake, refactor code (#58)
* Bump flake, refactor code * Add LambdaCase language extension * Bump hash * Update nix hash * Drop initialAction * Add `id_` * Remove IDs from plus and minus buttons
1 parent c386c04 commit f63bf69

7 files changed

Lines changed: 119 additions & 120 deletions

File tree

README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,15 @@ This file contains a simple `miso-lynx` counter application.
120120
-----------------------------------------------------------------------------
121121
module Main where
122122
-----------------------------------------------------------------------------
123-
import Miso
123+
import Miso hiding (text_)
124124
import Miso.Lynx
125+
import Miso.Lynx.Element.View.Event (onTap)
125126
-----------------------------------------------------------------------------
126127
import Miso.Lens
127128
import Miso.String
128-
import qualified Miso.Style as CSS
129+
import qualified Miso.CSS as CSS
129130
-----------------------------------------------------------------------------
131+
-- | Application model
130132
newtype Model = Model { _value :: Int }
131133
deriving (Show, Eq, ToMisoString)
132134
-----------------------------------------------------------------------------
@@ -136,15 +138,12 @@ value = lens _value $ \m v -> m { _value = v }
136138
data Action
137139
= AddOne
138140
| SubtractOne
139-
| SayHelloWorld
140-
| Tap Int
141141
deriving (Show, Eq)
142142
-----------------------------------------------------------------------------
143-
-- | Entry point for a miso-lynx application
143+
-- | Entry point for a miso application
144144
main :: IO ()
145145
main = run $ lynx counterComponent
146146
{ events = lynxEvents
147-
, initialAction = Just SayHelloWorld
148147
}
149148
-----------------------------------------------------------------------------
150149
counterComponent :: App Model Action
@@ -153,14 +152,11 @@ counterComponent = component (Model 0) updateModel viewModel
153152
updateModel
154153
:: Action
155154
-> Transition Model Action
156-
updateModel SayHelloWorld =
157-
io_ (consoleLog "Hello World!")
158-
updateModel AddOne =
159-
value += 1
160-
updateModel SubtractOne =
161-
value -= 1
162-
updateModel (Tap x) =
163-
io_ $ consoleLog ("Tapped: " <> ms (show x))
155+
updateModel = \case
156+
AddOne ->
157+
value += 1
158+
SubtractOne ->
159+
value -= 1
164160
-----------------------------------------------------------------------------
165161
-- | Constructs a virtual DOM from a model
166162
viewModel :: Model -> View Model Action

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ allow-newer:
1010
source-repository-package
1111
type: git
1212
location: https://github.com/dmjio/miso.git
13-
tag: 17f1c94aa5c037f230cea023e30e0a22979162a0
13+
tag: c85449e47af6581088cb9dde81cfcbf951232cff

examples/counter/Main.hs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-----------------------------------------------------------------------------
2+
{-# LANGUAGE LambdaCase #-}
23
{-# LANGUAGE RecordWildCards #-}
34
{-# LANGUAGE OverloadedStrings #-}
45
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@@ -11,7 +12,7 @@ import Miso.Lynx.Element.View.Event (onTap)
1112
-----------------------------------------------------------------------------
1213
import Miso.Lens
1314
import Miso.String
14-
import qualified Miso.Style as CSS
15+
import qualified Miso.CSS as CSS
1516
-----------------------------------------------------------------------------
1617
-- | Application model
1718
newtype Model = Model { _value :: Int }
@@ -23,15 +24,12 @@ value = lens _value $ \m v -> m { _value = v }
2324
data Action
2425
= AddOne
2526
| SubtractOne
26-
| SayHelloWorld
27-
| Tap Int
2827
deriving (Show, Eq)
2928
-----------------------------------------------------------------------------
3029
-- | Entry point for a miso application
3130
main :: IO ()
3231
main = run $ lynx counterComponent
3332
{ events = lynxEvents
34-
, initialAction = Just SayHelloWorld
3533
}
3634
-----------------------------------------------------------------------------
3735
counterComponent :: App Model Action
@@ -40,14 +38,11 @@ counterComponent = component (Model 0) updateModel viewModel
4038
updateModel
4139
:: Action
4240
-> Transition Model Action
43-
updateModel SayHelloWorld =
44-
io_ (consoleLog "Hello World!")
45-
updateModel AddOne =
46-
value += 1
47-
updateModel SubtractOne =
48-
value -= 1
49-
updateModel (Tap x) =
50-
io_ $ consoleLog ("Tapped: " <> ms (show x))
41+
updateModel = \case
42+
AddOne ->
43+
value += 1
44+
SubtractOne ->
45+
value -= 1
5146
-----------------------------------------------------------------------------
5247
-- | Constructs a virtual DOM from a model
5348
viewModel :: Model -> View Model Action
@@ -61,7 +56,6 @@ viewModel m = view_
6156
]
6257
[ view_
6358
[ onTap AddOne
64-
, id_ "plus"
6559
, CSS.style_
6660
[ CSS.backgroundColor CSS.yellow
6761
, CSS.width "100px"
@@ -100,7 +94,6 @@ viewModel m = view_
10094
]
10195
, view_
10296
[ onTap SubtractOne
103-
, id_ "minus"
10497
, CSS.style_
10598
[ CSS.backgroundColor CSS.pink
10699
, CSS.width "100px"

flake.lock

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

nix/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ options:
22
with (builtins.fromJSON (builtins.readFile ./nixpkgs.json));
33
let
44
nixpkgs = builtins.fetchTarball {
5-
url = "https://github.com/alexfmpe/nixpkgs/archive/${rev}.tar.gz";
5+
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
66
inherit sha256;
77
};
88
config = {

nix/nixpkgs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"rev" : "b594b289740a2bc917ed9c66fef5d905f389cb96",
3-
"sha256" : "sha256:1p25582cbrjlqv4kr64481m776vgppgxghinrdjpfjglkjj3aw2w"
2+
"rev" : "9e2e8a7878573d312db421d69e071690ec34e98c",
3+
"sha256" : "sha256:1q6fh1mx2b4fxbbh8n1h3888mx4n9p15s92mlcczcryqw09wvs0c"
44
}

0 commit comments

Comments
 (0)