I have a seesaw ui with a text editor. The editor content is backed by a record called 'Task' which is contained somewhere in an atom called 'state'. A key-released event on the editor should change the property :desc of the Task. I use the following code:
(def state
(atom {:tasks []
:interval nil
:style (style :foreground :black :background nil)}))
(defn on-text-edited [ui listener-fn]
(let [editor (select ui [:#editor])]
(listen editor :key-released
(fn [evt] (listener-fn (text editor))))))
(defn update-task! [task text]
(let [newtask (assoc task :desc text)
tasks (replace {task newtask} (:tasks @state))]
(swap! state
#(assoc % :tasks tasks))))
(def text-updates (on-text-edited frame #(update-task! selected-task %)))
selected-task is an atom referencing the current content model of the editor. Whenever the user edits text the update-task! function is supposed to be called. But nothing happens. The function seems not to be called at all. When I call it from the repl it behaves as expected.
I tested if the function would get called by letting it do a simple println:
(defn update-task! [task text]
(println (str task " " text)))
Now the function works fine when I edit text in the editor. Then I changed it to:
(defn update-task! [task text]
(let [newtask (assoc task :desc text)
tasks (replace {task newtask} (:tasks @state))]
(println (str task " " text))))
now again, it would do nothing at all. So it seems that somehow the accessing of the atoms get in the way of the event handling. Is there maybe a conflict between the ui thread and the thread the atoms were defined in?