Skip to content

Instantly share code, notes, and snippets.

@ricma
Last active August 29, 2015 14:19
Show Gist options
  • Save ricma/97d19fe29c07a95d1987 to your computer and use it in GitHub Desktop.
Save ricma/97d19fe29c07a95d1987 to your computer and use it in GitHub Desktop.
Test binding in Clojure App using Seesaw

Problem

In this other app I keep getting a IllegalStateException: Attempt to mutate in notification. Maybe this simplified example helps me solving it!

Running it

Simply type lein run.

(ns problem
"Test two-way bindings on text fields"
(:use [seesaw.core]
[seesaw.bind :only [bind b-swap! tee transform]])
(:gen-class))
(defn -main
"Create a frame with a text field, bind it to an atom"
[& args]
(let [s (label)
t (text)
u (text :enabled? false)
a (atom {:text ""})]
;; In this other project I keep getting a
;; IllegalStateException: Attempt to mutate in notification
;; ...
(bind
a (tee
(bind (transform :text) s)
(bind (transform :text) t)
(bind (transform :text) u)))
(bind t
(b-swap! a #(assoc %1 :text %2)))
;; just for debugging
(add-watch a :state-update
(fn [key ref old new]
(println (str "state changed to" new))))
(-> (frame :title "test binding"
:on-close :exit
:content (vertical-panel
:items [s t u])) pack! show!)))
(defproject binding-problem "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[seesaw "1.4.5"]]
:source-paths ["./"]
:main ^:skip-aot problem
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment