title: Handing event-driven programming in Clojure/ClojureScript
body: <p>I am trying understand how to model events in ClojureScript. Designing an event queue in JavaScript is easy. You just keep a (mutable) array of functions, and provide helper functions to add or remove callbacks from the array. When you trigger the event, just go through all callbacks listed in the array and invoke them one after the other.</p>
  
  <p>This paradigm is far from functional style - for instance there is no point in triggering the callbacks unless they have side effects. Moreover it is implemented using a mutable array. Still it seems to me that in ClojureScript one needs to be able to do event-driven programming to do anything useful. Now, I know that Google Closure already implements an event library, but my question is about implementing it natively.</p>
  
  <p>Since all basic Clojure/ClojureScript data types are immutable, what would be an idiomatic way to implement this mechanism? Changing a ref? Resorting to mutable data structures from the host (Java resp JavaScript)?</p>
  
  <p>If I understand correctly, agents are possibly the right tool in Clojure, but I see they are currently not implemented in ClojureScript.</p>