| This is where "event switching" comes in. Unfortunately, I have not used Elm or FlapJax, so I am not sure if the terminology is the same there. Traditional FRP has two main concepts: behaviors, which are values that can change continually, and stream of events. Scanning over this blog post, these ideas correspond roughly to Properties and EventStreams respectively in Bacon.js. Event switching is just having an event stream that itself contains behaviors. There's a great blog post[1] about this using Reactive Banana and Haskell. [1]: http://apfelmus.nfshost.com/blog/2012/09/03-frp-dynamic-even... Most of the post is fairly Haskell-specific, talking about the type system, but the basic idea should be applicable here as well. The running example is a bar tab. You want to be able to create new entries in the tab, which are just text entries that give you a price. So you would create something like entries :: Event [Behavior Price]
That is, you have a stream of events that contains behaviors corresponding to each text entry widget you've added. This makes calculating things like the sum of all the widgets relatively easy.I'm not sure how other libraries support this dynamic event switching though. My understanding is that it is somewhat tricky to implement efficiently. |
Helpful diagrams: https://github.com/raimohanska/bacon.js/wiki