threepenny-gui で IORef を設定しようとしていますが、うまくいきません。私のアプリでは、IORef 自体はより複雑になり、それ自体は表示されませんが、この例は私が考える問題を示しています。
これが私の試みです:
testIORef2 :: IORef String -> Window -> UI ()
testIORef2 ref window = void $ do
return window # set title "Test IORef"
inCell <- UI.input
outCell <- UI.input
getBody window #+ [
column [
grid [[string " In cell::", element inCell]
,[string "Out cell::" , element outCell ]]
, string "Cells should update while typing."
]]
-- When value changes write to IORef
on UI.valueChange inCell $ \_ -> do
inValue <- get value inCell
liftIO $ writeIORef ref inValue
-- Read the IORef
refVal <- liftIO $ readIORef ref
-- Behaviour which holds the string value in the input cell
inValue <- stepper "0" $ UI.valueChange inCell
-- Behaviour which holds the value in the ref
let outValue = (const refVal) <$> inValue
-- Set the value of the output cell to the outValue
element outCell # sink value outValue
コードの並べ替えは機能しますが、outValue は最新ではありません。
更新が時間どおりになるように修正するにはどうすればよいですか。また、コードの改善は大歓迎です。
ありがとう。