   (:require-macros [cljs.core.async.macros :refer [go-loop]])
   (:require [re-frame.db :refer [app-db]]
             [re-frame.utils :refer [first-in-vector]]
-            [cljs.core.async :refer [chan put! <!]]))
+            [cljs.core.async :refer [chan put! <! timeout]]))
 
 
 ;; -- register of handlers ------------------------------------------------------------------------

(def ^:private dispatch-chan  (chan))

(defn dispatch
  "reagent components send events by calling this function.
  Usage example:
     (dispatch [:delete-item 42])"
  [event-v]

  (go-loop []
      (let [event-v     (<! dispatch-chan)]
        (dispatch-sync event-v)
        (<! (timeout 0))     ;; just in case we are handling one dispatch after an other, give the GU a chance to do its stuff.
        (recur))))

(router)  ;; run the router loop it
