Created
March 7, 2018 22:43
-
-
Save ali-abrar/3577a12117abf08f69a89fcd20145801 to your computer and use it in GitHub Desktop.
reflex-dom issue #208
This file contains hidden or 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
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE TupleSections #-} | |
import Control.Arrow ((&&&)) | |
import Control.Monad.IO.Class (liftIO) | |
import qualified Data.Map as Map | |
import Data.Text (Text) | |
import qualified Data.Text as T | |
import Reflex.Dom | |
main :: IO () | |
main = mainWidget $ dropDownWReset >> return () | |
dropDownWReset :: (Reflex t, MonadWidget t m) => m (Dynamic t (Maybe (Int,Text))) | |
dropDownWReset = do | |
reset <- button "reset" | |
performEvent_ $ liftIO . putStrLn . show <$> reset | |
let cfg = def & dropdownConfig_setValue .~ (traceEvent "reset" $ 0 <$ reset) | |
dd <- dropdown 0 menu cfg | |
let dk = _dropdown_value dd | |
de = _dropdown_change dd | |
dk' <- holdDyn 0 de | |
let v = toOut <$> dk <*> menu | |
v' = toOut <$> dk' <*> menu | |
display =<< count reset | |
text ", " >> display v >> text ", " >> display v' | |
return v | |
where | |
toOut k m = (k,) <$> Map.lookup k m | |
menu = pure . Map.fromList . map (id &&& tshow) $ [0..3] | |
tshow = T.pack . show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment