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