using threepenny-gui/reactive in client/server programming

无人久伴 提交于 2019-12-04 18:14:32

Here is a piece of code. I will add description a bit later.

{-# LANGUAGE LambdaCase #-}
import Graphics.UI.Threepenny as UI


main :: IO ()
main = do
  (evFillList, doFillList) <- newEvent
  initialList <- valuesSupply ""
  behFillList <- stepper initialList evFillList

  startGUI defaultConfig $ \win -> do
    list <- ul
    sel <- listBox
        behFillList
        (pure Nothing)
        (pure $ \it -> UI.span # set text it)

    getBody win #+ [grid [[element list, element sel]]]
    setFocus $ getElement sel

    on selectionChange (getElement sel) $ \case
      Nothing -> return ()
      Just ix -> do
        items <- currentValue behFillList
        let it = items !! ix
        liftIO $ valuesSupply it >>= doFillList
        element list #+ [li # set html it]
        setFocus $ getElement sel


valuesSupply :: String -> IO [String]
valuesSupply x = return [x ++ show i | i <- [0..9]]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!