 (defprotocol IReadable
   (-read [this path]))
 
-(defn read [store path]
-  (when *component*
-    (register-path *component* store path))
-  (-read store path))
+(defn read
+  ([store path] (read store path nil))
+  ([store path default]
+     (when *component*
+       (register-path *component* store path))
+     (let [res (-read store path)]
+       (if res res default))))
 
 
 (defprotocol ITransact

(defn store [obj]
  (-store obj))

(defprotocol INotify
  (-notify [this path]))


    (notify-update path dep-graph)))




;; ---------------------------------------------------------------------
;; Helper Functions


(defn add-to [type container value]
  (if (empty? container)
    (conj type value)
    (conj container value)))


(defn register-path [component store path]
  (aset component "_paths"
        (add-to #{} (aget component "_paths") [store path])))


(defn build-path
  ([path-parts] (build-path [] path-parts))
  ([seed [part & rparts]]
     (cond
      (nil? part)
      seed

      (satisfies? IPath part)
      (concat seed (path part))

      :else
      (conj seed path))))


(defn cleanup [component]
  (let [paths (aget  component "_paths")]
    (doseq [[db path] paths]
      (remove-dep! db component path))))

;; ---------------------------------------------------------------------
;; Simple Store Cursor
