 (defn- app [config view]
   {:config config
    :worker (agent nil)
-   :state  (atom {:ui    {:view       view
-                          :model      {}
-                          :dirty?     false 
-                          :rendering? false}
+   :state  (atom {:ui    {:view  view
+                          :model {:inputs     {}
+                                  :dirty?     false
+                                  :locked     0
+                                  :rendering? false}}
                   :model {}})})
-
-(defn- rendering? [app]
-  (-> app :state deref :ui :rendering?))
 
 (defn- event-handler [app]
   (fn [& args]
-    (when-not (rendering? app)
-      (apply on-event app args))))
+    (apply on-event app args)))
 
 (defn start [config]
   @(gui/gui-do

  
    :author "Frank Mosebach"}
  (:require
    [fm.simrunner.gui (core :as gui) 
                      (view :as view) 
                      (wiring :as wiring)]))

(defmulti on-action {:private true} (fn [action & _] action))

(defmethod on-action :open-config [_ app & args]
  (println (format "open-config{args: %s}" args))
  (gui/choose-file (-> args first :widget) :title "Open Config"))  

(defmethod on-action :default [action app & args]
  (println (format "on-action{action: %s args: %s}" action args)))

(defmulti on-event {:private true} (fn [_ event-id & _] event-id))

(defmethod on-event :action-performed [app _ & args]
  (on-action (-> args first meta :action) app args))

(defmethod on-event :default [app event-id & args]
  (println (format "on-event{id: %s args: %s}" event-id args)))

      (.setTitle frame "SimRunner (c) 2014 DEINC")
      (.show frame))))

(defn- start-rendering [app-state]
  (assoc-in app-state [:ui :model :rendering?] true))

(defn- start-rendering! [{app-state :state}]
  (when (-> @app-state :ui :model :dirty?)
    (swap! app-state start-rendering)))

(defn- stop-rendering [app-state]
  (-> app-state 
      (assoc-in [:ui :model :rendering?] false)
      (assoc-in [:ui :model :dirty?] false)))

(defn- stop-rendering! [{app-state :state}]
  (when (-> @app-state :ui :model :rendering?)
    (swap! app-state stop-rendering)))

(defn render [app]
  (gui/gui-do
    (when (start-rendering! app)
      (try
        (io! "Do not update the ui in a transaction!")
        (finally
          (stop-rendering! app))))))

