sharkdp / purescript-flare

A special-purpose UI library for Purescript
287 stars 17 forks source link

Added foldEffect from Signal that works on the UI type #34

Closed KovaxG closed 4 years ago

KovaxG commented 4 years ago

This is needed for functionality described in this issue: https://github.com/sharkdp/purescript-flare/issues/33

sharkdp commented 4 years ago

Thank you very much for reporting this and for proposing a solution!

You have a button that says "INC" and a number. If you press "INC" the number will increase. When the number hits 10, a new button will appear that says "RESET". If you press it the number will reset to 0, and the "RESET" button will disappear.

If you want and find the time, I think that would be a great example to add to the examples in html/index.html / test/Main.purs.

KovaxG commented 4 years ago

I would add the implementation, but the code is a bit messy, since I need stuff like channels and wrapped signals to do it. I think I should add the framework function I described in the issue. However that might be a bit of a weird function signature, do you think I should add it simply to Flare?

I'm talking about this:

play :: forall s i r. Eq s
          => s
          -> (s -> UI i)
          -> (i -> s -> s)
          -> (s -> r)
          -> Effect (UI r)
play s0 modIn update render = do
  stateChannel <- channel initialState
  pure $ map render
       $ foldEffect (\i -> (\s -> send stateChannel s $> s) <<< update i) s0
       $ innerFlare (wrap $ dropRepeats $ subscribe stateChannel) modIn
sharkdp commented 4 years ago

However that might be a bit of a weird function signature, do you think I should add it simply to Flare?

Hm, probably not. But thank you for considering!

I'll merge this in the current state. Let me know if I should tag a new release.