I am trying to understand how to model events in ClojureScript. Designing an event queue in JavaScript is easy. You simply save the (mutable) array of functions and provide helper functions to add or remove callbacks from the array. When you fire an event, just go through all the callbacks listed in the array and call them one by one.
This paradigm is far from functional style - for example, it makes no sense to run callbacks if they have no side effects. In addition, it is implemented using a mutable array. However, it seems to me that ClojureScript needs to do event-driven programming to do something useful. Now I know that Google Closure already implements an event library, but my question is how to implement it.
Since all basic Clojure / ClojureScript data types are immutable, what would be an idiomatic way to implement this mechanism? Link change? To resort to mutable data structures from the host (Java and JavaScript)?
If I understand correctly, agents are probably the right tool in Clojure, but I see that they are not currently implemented in ClojureScript.
Andrea
source share