doc
This commit is contained in:
parent
430bab5282
commit
d1d6a0d739
28
readme.md
28
readme.md
@ -65,18 +65,25 @@ export const App = () => {
|
||||
|
||||
```haskell
|
||||
type Item = {id :: String, title :: String, description :: String}
|
||||
data State = StateEmpty | StateErrored Error | StateGotItems (Array Item)
|
||||
data Action = Init
|
||||
data State
|
||||
= StateEmpty
|
||||
| StateErrored Error
|
||||
| StateGotItems (Array Item)
|
||||
|
||||
renderItem item = div [] [ p [] [text item.title]
|
||||
, span [className "small"] [text item.description]
|
||||
]
|
||||
data Action = ActionInit
|
||||
|
||||
renderItem item =
|
||||
div [] [ p [] [text item.title]
|
||||
, span
|
||||
[className "small"]
|
||||
[text item.description]
|
||||
]
|
||||
|
||||
renderApp StateEmpty = p [] [text "Loading..."]
|
||||
renderApp (StateErrored e) = p [className "error"] [text (message e)]
|
||||
renderApp (StateGotItems items) = map renderItem items
|
||||
|
||||
action Init = do
|
||||
action ActionInit = do
|
||||
response <- fetch (URL "/api/item") {method: Get}
|
||||
jsonString <- text response
|
||||
itemsOrError <- readJSON jsonString
|
||||
@ -87,10 +94,11 @@ action Init = do
|
||||
app = mkComponent
|
||||
{ initialState: StateEmpty
|
||||
, render: renderApp
|
||||
, eval: mkEval ( defaultEval { handleAction = action
|
||||
, initialize: Just Init
|
||||
}
|
||||
)
|
||||
, eval:
|
||||
mkEval ( defaultEval { handleAction = action
|
||||
, initialize: Just ActionInit
|
||||
}
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user