Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: '15'
node-version: '22'
cache: 'npm'

- uses: purescript-contrib/setup-purescript@main

- name: Cache PureScript dependencies
uses: actions/cache@v2
uses: actions/cache@v4
# This cache uses the .dhall files to know when it should reinstall
# and rebuild packages. It caches both the installed packages from
# the `.spago` directory and compilation artifacts from the `output`
Expand Down
15 changes: 8 additions & 7 deletions benchmarks/js-framework-benchmark/keyed/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import Prelude
import Data.Array ((!!))
import Data.Array as DA
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Effect.Uncurried (EffectFn2)
import Effect.Uncurried as EU
import Flame (Html, ListUpdate, QuerySelector(..), (:>))
import Flame (Html, Update)
import Flame as F
import Flame.Html.Attribute as HA
import Flame.Html.Element as HE

import Flame.Types(NodeData)
import Flame.Types (NodeData)
import Web.DOM.ParentNode (QuerySelector(..))

data Message =
Create Int |
Expand Down Expand Up @@ -52,7 +53,7 @@ createRandomNRows n lastID = liftEffect (EU.runEffectFn2 createRandomNRows_ n la

main :: Effect Unit
main = F.mount_ (QuerySelector "body") {
init: model :> [],
model: model,
subscribe: [],
view,
update
Expand Down Expand Up @@ -133,15 +134,15 @@ spacer = HE.td' [ HA.class' "col-md-6" ]
footer :: Html Message
footer = HE.span' [ HA.class' "preloadicon glyphicon glyphicon-remove", HA.createAttribute "aria-hidden" "true" ]

update :: ListUpdate Model Message
update :: Update Model Message
update model =
case _ of
Create amount -> model :> [map (\rows -> Just (DisplayCreated rows)) (createRandomNRows amount model.lastID)]
Create amount -> model /\ [map (\rows -> Just (DisplayCreated rows)) (createRandomNRows amount model.lastID)]
DisplayCreated rows -> F.noMessages (model { lastID = model.lastID + DA.length rows, rows = rows })

AppendOneThousand ->
let amount = 1000
in model :> [map (\rows -> Just (DisplayAppended rows)) (createRandomNRows amount model.lastID)]
in model /\ [map (\rows -> Just (DisplayAppended rows)) (createRandomNRows amount model.lastID)]
DisplayAppended newRows -> F.noMessages (model { lastID = model.lastID + DA.length newRows, rows = model.rows <> newRows })

UpdateEveryTenth -> F.noMessages model { rows = DA.mapWithIndex updateLabel model.rows }
Expand Down
17 changes: 8 additions & 9 deletions benchmarks/js-framework-benchmark/non-keyed/src/Main.purs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module Main where

import Prelude (Unit, bind, map, mod, pure, show, (+), (/=), (<>), (==), otherwise)

import Data.Array ((!!))
import Data.Array as DA
import Data.Maybe (Maybe(..))
Expand All @@ -10,12 +8,13 @@ import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Effect.Uncurried (EffectFn2)
import Effect.Uncurried as EU
import Flame.Application.EffectList (ListUpdate)
import Flame.Types((:>), Html, NodeData)
import Web.DOM.ParentNode(QuerySelector(..))
import Flame as F
import Flame.Application.EffectList as F
import Flame.Html.Attribute as HA
import Flame.Html.Element as HE
import Flame.Types ((/\), Html, NodeData)
import Prelude (Unit, bind, map, mod, pure, show, (+), (/=), (<>), (==), otherwise)
import Web.DOM.ParentNode (QuerySelector(..))

data Message =
Create Int |
Expand Down Expand Up @@ -52,7 +51,7 @@ createRandomNRows n lastID = liftEffect (EU.runEffectFn2 createRandomNRows_ n la

main :: Effect Unit
main = F.mount_ (QuerySelector "main") {
init: model :> [],
model: model,
view,
subscribe: [],
update
Expand Down Expand Up @@ -133,15 +132,15 @@ spacer = HE.td' [ HA.class' "col-md-6" ]
footer :: Html Message
footer = HE.span' [ HA.class' "preloadicon glyphicon glyphicon-remove", HA.createAttribute "aria-hidden" "true" ]

update :: ListUpdate Model Message
update :: Update Model Message
update model =
case _ of
Create amount -> model :> [map (\rows -> Just (DisplayCreated rows)) (createRandomNRows amount model.lastID)]
Create amount -> model /\ [map (\rows -> Just (DisplayCreated rows)) (createRandomNRows amount model.lastID)]
DisplayCreated rows -> F.noMessages (model { lastID = model.lastID + DA.length rows, rows = rows })

AppendOneThousand ->
let amount = 1000
in model :> [map (\rows -> Just (DisplayAppended rows)) (createRandomNRows amount model.lastID)]
in model /\ [map (\rows -> Just (DisplayAppended rows)) (createRandomNRows amount model.lastID)]
DisplayAppended newRows -> F.noMessages (model { lastID = model.lastID + DA.length newRows, rows = model.rows <> newRows})

UpdateEveryTenth -> F.noMessages model { rows = DA.mapWithIndex updateLabel model.rows }
Expand Down
25 changes: 12 additions & 13 deletions docs/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ A Flame application consists of the following record

```haskell
type Application model message = {
init :: model,
model :: model,
view :: model -> Html message,
update :: model -> message -> model,
update :: Update model message,
subscribe :: Array (Subscription message)
}
```
Expand All @@ -31,11 +31,11 @@ that is, the state of our application is a single integer. In a real world appli
With our model type declared, we can define the initial state of the application

```haskell
init :: Model
init = 0
model :: Model
model = 0
```

The first time the application is rendered, Flame calls the view function with `init`.
The first time the application is rendered, Flame calls the view function with `model`.

### Application markup

Expand Down Expand Up @@ -67,13 +67,13 @@ data Message = Increment | Decrement
and thus our update function looks like

```haskell
update :: Model -> Message -> Model
update :: Update Model Message
update model = case _ of
Increment -> model + 1
Decrement -> model - 1
Increment -> model + 1 /\ []
Decrement -> model - 1 /\ []
```

See [Handling events](events) for an in depth look at update strategies.
See [Handling events](events) for an in depth look at updates.

### Subscriptions

Expand All @@ -84,19 +84,18 @@ In the counter example no external events are handled, so the subscription list
```haskell
subscribe :: Array (Subscription Message)
subscribe = []
}
```

See [Handling external events](events#handling-external-events) for an in depth look at subscriptions.
See [Subscriptions](events#subscriptions) for an in depth look at subscriptions.

### Rendering

Having all pieces put together, we can either render the application to the DOM, as in the case of the counter example

```haskell
main :: Effect Unit
main = FAN.mount_ (QuerySelector "body") {
init,
main = F.mount_ (QuerySelector "body") {
model,
view,
update,
subscribe
Expand Down
Loading
Loading