Hot-reload registry built on clj-reload.
Extends tonsky/clj-reload with:
Design: Composition over reimplementation.
Hot-reload registry built on clj-reload. Extends tonsky/clj-reload with: - Named component registry - Event-driven listeners (for hive-events integration) - Status tracking and introspection - Cascade control - Watcher integration with coordinated debouncing Design: Composition over reimplementation.
(add-listener! listener-id listener-fn)Add a reload event listener.
Events:
Add a reload event listener.
Events:
- {:type :reload-start}
- {:type :reload-success :unloaded [...] :loaded [...] :ms elapsed}
- {:type :reload-error :failed ns :error ex}
- {:type :component-callback :component id :callback :on-reload|:on-error}(find-namespaces pattern)Find namespaces matching a pattern. Delegates to clj-reload/find-namespaces.
Find namespaces matching a pattern. Delegates to clj-reload/find-namespaces.
(get-component component-id)Get component registration by ID.
Get component registration by ID.
(init!)(init! opts)Initialize hive-hot with source directories.
Options (passed to clj-reload/init):
Example:
(init! {:dirs ["src" "dev"]
:no-reload '#{user}})
Initialize hive-hot with source directories.
Options (passed to clj-reload/init):
- :dirs - Source directories (default: ["src"])
- :no-reload - Namespaces to never reload
- :no-unload - Namespaces to reload but not unload
Example:
```clojure
(init! {:dirs ["src" "dev"]
:no-reload '#{user}})
```(init-with-watcher!)(init-with-watcher!
{:keys [dirs claim-checker debounce-ms no-reload no-unload]
:or {dirs ["src"] claim-checker (constantly #{}) debounce-ms 100}})Initialize hive-hot with file watcher and coordinating debouncer.
This wires together:
Options:
The claim-checker is typically created via:
(events/make-claim-checker logic/get-all-claims)
When a file changes:
Example:
;; Basic usage (no coordination)
(init-with-watcher! {:dirs ["src" "dev"]})
;; With claim-aware coordination
(init-with-watcher!
{:dirs ["src"]
:claim-checker (events/make-claim-checker logic/get-all-claims)})
Returns :watching on success.
Initialize hive-hot with file watcher and coordinating debouncer.
This wires together:
- FileWatcher (from hive-hot.watcher)
- CoordinatingDebouncer (from hive-hot.debounce)
- reload! for actual reloading
Options:
- :dirs - Source directories to watch (default: ["src"])
- :claim-checker - Function returning set of claimed files
(default: (constantly #{}))
- :debounce-ms - Debounce window in ms (default: 100)
- :no-reload - Namespaces to never reload
- :no-unload - Namespaces to reload but not unload
The claim-checker is typically created via:
```clojure
(events/make-claim-checker logic/get-all-claims)
```
When a file changes:
1. FileWatcher detects change
2. Debouncer checks claim-checker
- If file is claimed: buffer until released
- If unclaimed: apply debounce-ms window
3. After debounce: emit :file/changed, call reload!
Example:
```clojure
;; Basic usage (no coordination)
(init-with-watcher! {:dirs ["src" "dev"]})
;; With claim-aware coordination
(init-with-watcher!
{:dirs ["src"]
:claim-checker (events/make-claim-checker logic/get-all-claims)})
```
Returns :watching on success.(list-components)List all registered component IDs.
List all registered component IDs.
(reg-hot component-id {:keys [ns on-reload on-error] :as opts})Register a component for hot-reload callbacks.
Options:
Note: clj-reload handles dependency tracking automatically. Use this for application-level callbacks (restart server, etc).
Example:
(reg-hot :http-server
{:ns 'my.server
:on-reload #(println "Server code reloaded!")})
Register a component for hot-reload callbacks.
Options:
- :ns - Namespace symbol (required)
- :on-reload - Callback after successful reload (fn [])
- :on-error - Callback on reload failure (fn [exception])
Note: clj-reload handles dependency tracking automatically.
Use this for application-level callbacks (restart server, etc).
Example:
```clojure
(reg-hot :http-server
{:ns 'my.server
:on-reload #(println "Server code reloaded!")})
```(reload!)(reload! opts)Reload changed namespaces and their dependents.
Options (passed to clj-reload/reload):
Emits events via hive-events:
Returns: {:success bool :unloaded [ns ...] :loaded [ns ...] :failed ns-or-nil :error exception-or-nil :ms elapsed}
Example:
(reload!) ; Reload changed
(reload! {:only :all}) ; Reload everything
(reload! {:only #".*-test"}) ; Reload matching
Reload changed namespaces and their dependents.
Options (passed to clj-reload/reload):
- :throw - Throw on error (default: false, returns result map)
- :only - :loaded | :all | #"pattern"
Emits events via hive-events:
- :hot/reload-start before reload
- :hot/reload-success or :hot/reload-error after
Returns:
{:success bool
:unloaded [ns ...]
:loaded [ns ...]
:failed ns-or-nil
:error exception-or-nil
:ms elapsed}
Example:
```clojure
(reload!) ; Reload changed
(reload! {:only :all}) ; Reload everything
(reload! {:only #".*-test"}) ; Reload matching
```(reload-all!)Force reload of all namespaces.
Use sparingly - prefer reload! for incremental reloads.
Force reload of all namespaces. Use sparingly - prefer reload! for incremental reloads.
(remove-listener! listener-id)Remove a reload event listener.
Remove a reload event listener.
(reset-all!)Reset all registrations. Use in tests.
Reset all registrations. Use in tests.
(status)Get current hot-reload status.
Returns: {:initialized? bool :components {...} :listener-count n}
Get current hot-reload status.
Returns:
{:initialized? bool
:components {...}
:listener-count n}(stop-watcher!)Stop the file watcher if running.
Stop the file watcher if running.
(unreg-hot component-id)Unregister a component.
Unregister a component.
(watcher-status)Get watcher status.
Returns nil if not watching, or map with:
Get watcher status. Returns nil if not watching, or map with: - :watching? true - :dirs watched directories
(watching-paths)Get list of directories being watched. Returns empty vector if not watching.
Get list of directories being watched. Returns empty vector if not watching.
(with-reload & body)Execute body, then reload.
Useful for REPL development:
(with-reload
(spit "src/my/service.clj" new-code))
Execute body, then reload. Useful for REPL development: ```clojure (with-reload (spit "src/my/service.clj" new-code)) ```
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |