Liking cljdoc? Tell your friends :D

hive-hot.core

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.

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.
raw docstring

add-listener!clj

(add-listener! listener-id listener-fn)

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}
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}
sourceraw docstring

find-namespacesclj

(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.
sourceraw docstring

get-componentclj

(get-component component-id)

Get component registration by ID.

Get component registration by ID.
sourceraw docstring

init!clj

(init!)
(init! opts)

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:

(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}})
```
sourceraw docstring

init-with-watcher!clj

(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:

  • 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:

(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:

;; 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.
sourceraw docstring

list-componentsclj

(list-components)

List all registered component IDs.

List all registered component IDs.
sourceraw docstring

reg-hotclj

(reg-hot component-id {:keys [ns on-reload on-error] :as opts})

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:

(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!")})
```
sourceraw docstring

reload!clj

(reload!)
(reload! opts)

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:

(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
```
sourceraw docstring

reload-all!clj

(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.
sourceraw docstring

remove-listener!clj

(remove-listener! listener-id)

Remove a reload event listener.

Remove a reload event listener.
sourceraw docstring

reset-all!clj

(reset-all!)

Reset all registrations. Use in tests.

Reset all registrations. Use in tests.
sourceraw docstring

statusclj

(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}
sourceraw docstring

stop-watcher!clj

(stop-watcher!)

Stop the file watcher if running.

Stop the file watcher if running.
sourceraw docstring

unreg-hotclj

(unreg-hot component-id)

Unregister a component.

Unregister a component.
sourceraw docstring

watcher-statusclj

(watcher-status)

Get watcher status.

Returns nil if not watching, or map with:

  • :watching? true
  • :dirs watched directories
Get watcher status.

Returns nil if not watching, or map with:
- :watching? true
- :dirs watched directories
sourceraw docstring

watching-pathsclj

(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.
sourceraw docstring

with-reloadcljmacro

(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))
```
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close