I'm working on a GUI application in Swing+Clojure that requires various mutable pieces of data (e.g. scroll position, user data, filename, selected tool options etc.).
I can see at least three different ways of handling this set of data:
Create a ref to a map of all the data:
(def data (ref {
:filename "filename.xml"
:scroll [0 0] }))
Create a map of refs to the individual data elements:
(def datamap {
:filename (ref "filename.xml")
:scroll (ref [0 0]) }))
Create a separate ref for each in the namespace:
(def scroll (ref [0 0]))
(def filename (ref "filename.xml"))
Note: This data will be accessed concurrently, e.g. by background processing threads or the Swing event handling thread. However there probably isn't a need for consistent transactional updates of multiple elements.
What would be your recommended approach and why?