(ns-tracker dirs)
(ns-tracker dirs initial-timestamp-map)
Returns a no-arg function which, when called, returns a set of
namespaces that need to be reloaded, based on file modification
timestamps and the graph of namespace dependencies.
Source
(defn ns-tracker
"Returns a no-arg function which, when called, returns a set of
namespaces that need to be reloaded, based on file modification
timestamps and the graph of namespace dependencies."
([dirs]
(ns-tracker dirs (current-timestamp-map (normalize-dirs dirs))))
([dirs initial-timestamp-map]
{:pre [(map? initial-timestamp-map)]}
(let [dirs (normalize-dirs dirs)
timestamp-map (atom initial-timestamp-map)
[init-decls init-names] (newer-namespace-decls {} @timestamp-map)
dependency-graph (atom (update-dependency-graph (graph) init-decls))]
(fn []
(let [then @timestamp-map
now (current-timestamp-map (normalize-dirs dirs))
[new-decls new-names] (newer-namespace-decls then now)]
(when (seq new-names)
(let [affected-names (affected-namespaces new-names @dependency-graph)]
(reset! timestamp-map now)
(swap! dependency-graph update-dependency-graph new-decls)
affected-names)))))))