-
-
Save MuratOzsoyler/7fccd107916a76f37e1ae50fa239ec6d to your computer and use it in GitHub Desktop.
How to generate an array of widgets after waiting for an Aff action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Effect (Effect) | |
import Data.Either (Either (..)) | |
import Data.Traversable (traverse) | |
import Control.MultiAlternative (orr) | |
import Concur.Core (Widget) | |
import Concur.React (HTML) | |
import Concur.React.DOM (button, div', div_, text, table', th', tr', td, td', td_) | |
import Concur.React.Props (colSpan, onClick) | |
import Concur.React.Run (runWidgetInDom) | |
import Control.Alternative ((<|>)) | |
import Effect.Aff (delay) | |
import Effect.Aff.Class (liftAff) | |
import Data.Time.Duration (Milliseconds (..)) | |
waitEvent :: forall a. Array (Widget HTML a) | |
waitEvent = do | |
result <- liftAff (delay (Milliseconds 10000.0) *> pure (Right 1111)) <|> td_ [colSpan 2] (text "Loading...") | |
{- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
No type class instance was found for | |
Effect.Aff.Class.MonadAff Array | |
while applying a function liftAff | |
-} | |
case result of | |
Left err -> do | |
void $ td [colSpan 2] | |
[ text $ "Error occured: " <> err | |
, button [onClick] [text "Retry"] | |
] | |
waitEvent | |
Right res -> | |
[ td' [text $ "Value is=" <> show res] | |
, td' $ text "Finished" | |
] | |
main :: Effect Unit | |
main = runWidgetInDom "main" $ table' | |
[ tr' | |
[ th' [text "col1"] | |
, th' [text "col2"] | |
, th' [text "col3"] | |
, th' [text "col4"] | |
] | |
, tr' | |
[ td' [text "1"] | |
, td' [text "2"] | |
] <> waitEvent | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the code with all of these modifications made -