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

Async calls in initializer in the latest version #21

Open
clayrat opened this issue Feb 9, 2016 · 2 comments
Open

Async calls in initializer in the latest version #21

clayrat opened this issue Feb 9, 2016 · 2 comments

Comments

@clayrat
Copy link

clayrat commented Feb 9, 2016

Is it possible now to do an async call to initialize a component? I have something like this, where I want an image loaded on startup and a button to reload it:

imageLoader = withAsync $ with \st h -> let
  setUrl u = updatePure h $ case u of
    Just a  -> st # imgUrl .~ Success a
    Nothing -> st # imgUrl .~ Failed unit
  reload = update h $ do
    async (JS.decode <<< _.response <$> (AJ.get someUrl)) (const Nothing)
    pure st
  in withView (H.div $ [ H.onInitialized "foo" $ const reload ]) $ mconcat
  [ imgUrl $ mconcat
    [ _Failed $ ui $ H.p_ $ text "error"
    , _Success $ with \s _ -> ui $ H.div_ $ H.img [ H.srcA $ extractUrl s ] mempty
    ]
  , ui $ H.button [ H.onClick $ const reload ] $ text "reload"
  , listen (const true) setUrl
  ]

But it doesn't seem to fire. Maybe it's possible to hook it up via the _Init prism somehow?

@clayrat
Copy link
Author

clayrat commented Feb 9, 2016

I mean, the button works, but the initializer does not.

@zrho
Copy link
Owner

zrho commented Feb 9, 2016

Oh, in theory this should work; probably there is something wrong with how initializers are attached to the vdom. I'll have a look at it as soon as possible.

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

No branches or pull requests

2 participants