<commit_before>(ns braid.core.hooks
  "Provides a way to register atoms that can later all be reset to their initial values.
   This enables changes to Braid modules to be picked up in a reloaded workflow (ie. figwheel).

  On the client-side:
  Figwheel is configured to call (braid.core.client.desktop.core/reload!),
  which calls (braid.core.modules/init!), which calls (reset-all!)

  On the server-side:
  (braid.core.modules/init!) is called once, when the server is started (in braid.core.server.core)."
  (:require
    [braid.core.common.util :as util]))

(defonce atoms (atom {}))

(defn register!
  "Takes an atom and adds it to a central registry so that it can be later reset to its initial value.
   Only the first registration of an atom is stored.
   Always returns the given atom."
  ([a data-spec]
   (when-not (contains? @atoms a)
     (swap! atoms assoc a @a))
   (when data-spec
     (set-validator! a (fn [x]
                         ;; use assert, to elide the code in prod
                         (assert (util/valid? data-spec x))
                         ;; assert returns nil
                         ;; but validator expects true<commit_msg>Update documentation<commit_after>(ns braid.core.hooks
  "Provides a way to register atoms that can later all be reset to their initial values.
   This enables changes to Braid modules to be picked up in a reloaded workflow (ie. figwheel).

  On the client-side:
  Figwheel is configured to call (braid.core.client.desktop.core/reload!),
  which calls (braid.core.modules/init!), which calls (reset-all!)

  On the server-side:
  (braid.core.modules/init!) is called once, when the server is started (in braid.core)."
  (:require
    [braid.core.common.util :as util]))

(defonce atoms (atom {}))

(defn register!
  "Takes an atom and adds it to a central registry so that it can be later reset to its initial value.
   Only the first registration of an atom is stored.
   Always returns the given atom."
  ([a data-spec]
   (when-not (contains? @atoms a)
     (swap! atoms assoc a @a))
   (when data-spec
     (set-validator! a (fn [x]
                         ;; use assert, to elide the code in prod
                         (assert (util/valid? data-spec x))
                         ;; assert returns nil
                         ;; but validator expects true
{'fraction_non_alphanumeric': 0.09344192027432491, 'fraction_numerical': 0.0, 'mean_word_length': 2.5150602409638556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4110585', 'n_tokens_mistral': 686, 'n_tokens_neox': 657, 'n_words': 286}