paf31 / purescript-behaviors

A simple push-pull FRP implementation
MIT License
133 stars 22 forks source link

How to handling non-animation side effects? #6

Closed mjleitch closed 7 years ago

mjleitch commented 7 years ago

Is animate the appropriate function for outputting behavior values to all side effects (i.e. console log, local storage, (v)dom)? Or is it just for canvas? For example, the following works in the browser but not in the console.

seconds :: Behavior Number
seconds = map ((_ / 1000.0) <<< toNumber) Time.millisSinceEpoch

main :: forall e. Eff (console :: CONSOLE, frp :: FRP | e) Unit
main = animate seconds logShow

Is there a more appropriate function built in to handle other non-animation side effects? Are behaviors even appropriate for things like dom updates, storing state, etc? Or is it really just for canvas animation and the like?

I'm coming from a RxJS (events only) mindset... so trying to wrap my head around behaviors is proving difficult.

paf31 commented 7 years ago

animate should work with any type of effects, but it requires requestAnimationFrame, so it won't work in the console.

In the console, you can sample on an Event, and subscribe to the result.