Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

liftIO in Widget causes strange behavior #8

Open
mpdairy opened this issue Nov 28, 2017 · 5 comments
Open

liftIO in Widget causes strange behavior #8

mpdairy opened this issue Nov 28, 2017 · 5 comments
Labels

Comments

@mpdairy
Copy link

mpdairy commented Nov 28, 2017

I'm working on a nifty way to do forms, which will also hopefully be able to handle text inputs that update every key press. However, I ran into my form elements returning some really weird results, and I narrowed it down to it being caused by widgets that have liftIO in them. For example, here's a Widget I made as I was trying to figure out the problem:

testNonStateT :: Widget HTML b
testNonStateT = forever $ do
  _ <- simStateT ("one", "two", "three")
  return ()
  where
    simStateT s = do
      r <- (do
               r <- inputEnter' $ s ^. _1
               liftIO $ print "hey there!"
               return $ s & _1 .~ r)
           <|>
           (do
               r <- inputEnter' $ s ^. _2
               liftIO $ print "hey there!"
               return $ s & _2 .~ r)
           <|>
           (do
               r <- inputEnter' $ s ^. _3
               liftIO $ print "hey there!"
               return $ s & _3 .~ r )
      liftIO $ print r
      simStateT r

inputEnter' :: String -> Widget HTML String
inputEnter' t = inputEnter [ A.value . JS.pack $ t ]

When I try this, the third one will work fine, but the second one gets the third input box's return value, and the first gets the second's. However, if I uncomment the liftIO $ print "hey there!" lines, it works fine.

I'm using Concur.VDOM.

@ajnsit
Copy link
Owner

ajnsit commented Nov 28, 2017

That's really weird. I'll take a look.

@ajnsit ajnsit added the bug label Nov 28, 2017
@ajnsit
Copy link
Owner

ajnsit commented Nov 28, 2017

From initial investigation it seems to be a bug in ghcjs-vdom. I'll look at it more later today.

@mpdairy
Copy link
Author

mpdairy commented Feb 9, 2018

Did you ever find out anything more about this? If it's just a vdom bug, would you recommend that I just use a different concur backend for now?

@ajnsit
Copy link
Owner

ajnsit commented Feb 9, 2018

I looked at it a little bit and then got busy with other things. Thanks for reminding me!

I'm still not sure if this is a GHCJS bug or a ghcjs-vdom bug. But I found a quick way to solve this - add some strictness. So for example you can use {-# LANGUAGE BangPatterns #-} and then do - !r <- inputEnter' $ s ^. _1 .

Of course if you wish, you can always use Concur-React instead of Concur-VDOM. The React backend doesn't seem to suffer from the same issue, and it's also relatively better maintained (Since ghcjs-vdom is bitrotten at this point).

@mpdairy
Copy link
Author

mpdairy commented Feb 9, 2018

Ok thanks! I'll try concur-react or fall back to using strictness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants