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

HasPostGui Equivalent in Reflex-Dom 0.4? #139

Open
mageshb opened this issue Mar 20, 2017 · 10 comments
Open

HasPostGui Equivalent in Reflex-Dom 0.4? #139

mageshb opened this issue Mar 20, 2017 · 10 comments

Comments

@mageshb
Copy link
Contributor

mageshb commented Mar 20, 2017

I'm trying to upgrade few of our libraries to make it compatible to latest reflex & reflex-dom.
I couldn't able to find the equivalent of HasPostGui in the latest version.

https://github.com/byteally/reflex-indexed-db/blob/master/src/Reflex/IDB.hs#L83-L103
In above code which works fine with hackage version of reflex & reflex-dom,
basically I'm able to use askPostGui, runWithActions to convert native indexed-db events to Reflex events.
How to get this functionality with the latest version?
I could see lot of changes between the latest version and the one in the hackage.
Is the latest reflex-dom is stable enough so that we can start porting the code to it or should we need to stick to the version available in the hackage for now?
Is there any idea when we can expect to see a next hackage release?

@qrilka
Copy link
Contributor

qrilka commented Mar 20, 2017

@mageshb there is reflex-frp/reflex#75 (unfortunately with no particular answer yet)
Regarding HasPostGui probably
https://www.reddit.com/r/reflexfrp/comments/5dnnsr/is_there_any_way_to_run_an_action_after_all/ could help you?

@mageshb
Copy link
Contributor Author

mageshb commented Mar 20, 2017

@qrilka Thank you, I'm able to make it work with those api changes

@qrilka
Copy link
Contributor

qrilka commented May 23, 2017

@ryantrinkle is there some new way to do that?
I have updated our app to new Reflex with jsaddle in it and all those hacks stopped to work. I've created a small example app - https://github.com/qrilka/reflex-inner-update/blob/master/src/Main.hs and running it in Chrome shows me

Number of SPANs: 0

but I need some way to get 2 instead - i.e. run that code "post gui".
Maybe #152 is somehow related?

@Dridus
Copy link

Dridus commented May 23, 2017

it's definitely similar, though in your example code I think there's a misunderstanding - the spans won't exist until the button is pressed. You could use the support from #152 inside the widgetHold to wait until those spans are mounted (after the button is pressed) and it shouild report 2 at that time.

@qrilka
Copy link
Contributor

qrilka commented May 24, 2017

@Dridus that's not a misunderstanding - that's the requirement :)
And regarding widgetHold - as I understand that will work once - what if I need to react on any Event not only the 1st?
What I actually need is some way to run code after all Reflex UI updates finish for particular event.

@qrilka
Copy link
Contributor

qrilka commented May 24, 2017

After adding some delay code was working OK on a small page but in our app we load substantial amount of data so e.g. delay of 100ms isn't enough :(

@Dridus
Copy link

Dridus commented May 24, 2017

well, I think what you want is possible, but not as described, though it could be I'm misunderstanding what your requirement is. If the goal is to be notified from the origination of some event (i.e. the button press) that all consequential UI updates are complete, then that's not possible with the #152 code. However, if you don't mind observing this from the end point then you can do it, for example:

elWithChildren
  :: MonadWidget t m
  => Event t [Text] -> m ()
elWithChildren ev = do
 mountState <- fmap join . el "div" $
    widgetHold (text "Waiting" $> constDyn Mounting) $
    ffor ev $ \xs -> forM_ xs $ \x -> el "span" $ text x
  _ <- performEventAsync $ (\_ -> liftIO js_logSpans) <$ ffilter (== Mounted) mountState

i.e. within the widgetHold you can ask for a Dynamic representing when that chunk of DOM has been mounted.

@qrilka
Copy link
Contributor

qrilka commented May 24, 2017

@Dridus thanks.
That looks like a solution for dom creation use case (and it appears that I've seen #110 :) ).
And probably that will to for our app.
And regarding this code you pasted above - doesn't it miss getMountStatus call maybe? Otherwise I don't understand how could I get mount state out of forM_

@Dridus
Copy link

Dridus commented May 24, 2017

oh, yes, didn't compile it of course. corrected, hopefully:

elWithChildren
  :: MonadWidget t m
  => Event t [Text] -> m ()
elWithChildren ev = do
 mountState <- fmap join . el "div" $
  widgetHold (text "Waiting" $> constDyn Mounting) $
    ffor ev $ \xs -> do
      forM_ xs $ \x -> el "span" $ text x
      getMountStatus
  _ <- performEventAsync $ (\_ -> liftIO js_logSpans) <$ ffilter (== Mounted) mountState

@Dridus
Copy link

Dridus commented May 24, 2017

and it's kinda #110. #110 comes up because of two cases (both overcome by #152):

  • the widget has other components which are notReady. when this happens, the DOM builder keeps track of how many children are not yet ready and each of those children decrements the count whenever they become ready. when the last one becomes ready, the whole DOM fragment is installed.
  • the widget is enclosed in some hierarchy where one of its ancestor widgets has not yet mounted

#152 gives a notification mechanism which keeps track of the parent mount state as well as the local one, and the local mount state is bumped to Mounted when the DOM fragment goes in (after all children become ready). those two states are zipped together with min, so that if a parent is Unmounted but the child is mounted (or vice versa) then the overall (visible) mount state is Unmounted. only when the parent and the child are both Mounted does the overall state become Mounted

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

No branches or pull requests

6 participants