<commit_before>(ns re-frame.history
  (:require-macros [reagent.ratom  :refer [reaction]]
                   [historian.core :refer [off-the-record]])
  (:require
    [reagent.core      :as     r]
    [re-frame.db       :refer [app-db]]
    [re-frame.handlers :as     handlers ]
    [re-frame.subs     :as     subs ]
    [historian.core    :as     historian]
    ))


;; -- data  --------------------------------------------------------------------------------------

(historian/record! app-db :db)
(def undo-list (r/atom []))
(def redo-list (r/atom []))
(historian/replace-library!  undo-list)
(historian/replace-prophecy! redo-list)

(defn reset-history!
  "privileged protocol: should not be used by client code"
  []
  (historian/clear-history!)
  (historian/trigger-record!))


;; -- subscriptions  -----------------------------------------------------------------------------

(subs/register
  :undos?
  (fn
    [_ _]
    "answer true is anything is stored in the undo list"
    (reaction (> (count @undo-list) 1))))

(subs/register
  :redos?
  (fn
    [_ _]
    "answer true is anything is stored in the redo list"
    (reaction (> (count @redo-list) 0))))

;; -- event handlers  ----------------------------------------------------------------------------

(handlers/register
  :undo
  (fn
    [_ _]
    (historian/undo!))) ;; (dispatch [:undo])


(handlers/register
  :redo
  (fn
    [_ _]
    (historian/redo!))) ;; (dispatch [:undo])


(handlers/register
  :no-history-while
  (fn
    [db [_ mutation-fn]]
    (off-the-record
      (reset! db (mutation-fn @app-db)))))
<commit_msg>- convert :no-history-while from dispatch to direct call off-the-record!<commit_after>(ns re-frame.history
  (:require-macros [reagent.ratom  :refer [reaction]]
                   [historian.core :refer [off-the-record]])
  (:require
    [reagent.core      :as     r]
    [re-frame.db       :refer [app-db]]
    [re-frame.handlers :as     handlers ]
    [re-frame.subs     :as     subs ]
    [historian.core    :as     historian]
    ))


;; -- data  --------------------------------------------------------------------------------------

(historian/record! app-db :db)
(def undo-list (r/atom []))
(def redo-list (r/atom []))
(historian/replace-library!  undo-list)
(historian/replace-prophecy! redo-list)

(defn reset-history!
  "privileged protocol: should not be used by client code"
  []
  (historian/clear-history!)
  (historian/trigger-record!))

(defn off-the-record!
  "evaluate db mutation-fn without creating a history record"
  [db mutation-fn]
  (off-the-record (reset! db (mutation-fn db))))


;; -- subscriptions  -----------------------------------------------------------------------------

(subs/register
  :undos?
  (fn
    [_ _]
    "answer true is anything is stored in the undo list"
    (reaction (> (count @undo-list) 1))))

(subs/register
  :redos?
  (fn
    [_ _]
    "answer true is anything is stored in the redo list"
    (reaction (> (count @redo-list) 0))))

;; -- event handlers  ----------------------------------------------------------------------------

(handlers/register
  :undo
  (fn
    [_ _]
    (historian/undo!))) ;; (dispatch [:undo])


(handlers/register
  :redo
  (fn
    [_ _]
    (historian/redo!))) ;; (dispatch [:undo])

{'fraction_non_alphanumeric': 0.2836553204538485, 'fraction_numerical': 0.0012266176019625882, 'mean_word_length': 1.63915857605178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5598508', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1026, 'n_words': 237}