             [cljsjs.codemirror.mode.clojure :as cm-clj]
             [cljs.pprint :as pp]
             [cljs.reader :as reader]
+            [clojure.string :as string]
             [dato.lib.core :as dato]
             [dato.debug.components.keyboard-listener :as keyboard]
             [om-bootstrap.panel :as bs-p]

                                                                       (js/console.log "--------------------")))}}))))
    om/IRender
    (render [_]
      (let [log                (:log data)
            log-count          (count log)
            dato               (om/get-shared owner [:dato])
            db                 (dato/db dato)
            app-root           (om/value (om/get-shared owner [:app-root]))
            selected-state-idx (max 0 (min (or (om/get-state owner [:states :selected]) 0) log-count))
            selected-state     (when (pos? log-count)
                                 (nth log selected-state-idx))
            set-app-state!     (fn [idx]
                                 (when-let [state (and (pos? log-count)
                                                       (get-in log [idx :tx :db-after]))]
                                   (let [new-db (om/value state)
                                         conn   (dato/conn dato)]
                                     (js/console.log "new-db: " new-db)
                                     (js/console.log "conn: " conn)
                                     (js/console.log "\t=>" [(type new-db)
                                                             (pr-str (type new-db))
                                                             (satisfies? datascript.core/ISearch new-db)
                                                             (satisfies? datascript.core/IIndexAccess new-db)
                                                             (satisfies? datascript.core/IDB new-db)])
                                     (reset! conn new-db)
                                     (om/refresh! app-root)
                                     (js/console.log "app-root: " app-root)
                                     ;; (js/console.log "Atom? " conn)
                                     ;; (js/console.log "new-db DB? " (datascript.core/db? new-db))
                                     ;; (js/console.log "DB? " (datascript.core/db? @conn))
                                     ;; (js/console.log "post-reset: " conn)
                                     )))
            play-all-states!   (fn play-all-states!
                                 ([]
                                  (play-all-states! 0))
                                 ([idx]
                                  (cond
                                    (> idx (dec log-count))          nil
                                    (get-in log [idx :tx :db-after]) (do
                                                                       (set-app-state! idx)
                                                                       (js/setTimeout #(play-all-states! (inc idx)) 1))
                                    :else                            (js/setTimeout #(play-all-states! (inc idx)) 1))))]
        (dom/div
         {:style {:display (when-not (om/get-state owner [:open?]) "none")}}
         (om/build keyboard/keyboard-handler {} {:opts {:keymap (atom {["ctrl+slash"] #(om/update-state! owner [:open?] not)})}})
         (dom/div
          {:className     "debugger"
           :on-mouse-move #(.stopPropagation %)}
          (bs-p/panel
           {:header (dom/div (dom/button {:on-click #(om/set-state! owner [:tool] :debugger)} "Debugger")
                             (dom/button {:on-click #(om/set-state! owner [:tool] :editor)} "Editor")
                             (dom/button {:on-click #(om/set-state! owner [:tool] :query)} "Expression Watch")
                             " - Dato Debugger " (dom/small "(" log-count " states)"))}
           (case (om/get-state owner [:tool])
             :query    (dom/div
                        (g/grid
                         {}

  (reify
    om/IWillMount
    (will-mount [_]
      (om/set-state! owner [:current-save-slot] 0)
      (om/set-state! owner [:tool] :states)
      (om/set-state! owner [:current-query] "default")
      (om/set-state! owner [:open?] false)
      (om/set-state! owner [:query] (or (:expressions opts) [])))
    om/IDidUpdate
    (did-update [_ _ prev]
