mirror of
https://github.com/status-im/re-frame.git
synced 2025-02-24 15:58:36 +00:00
Merge pull request #64 from danielcompton/small-changes
Clean up spelling, tense, and docstrings
This commit is contained in:
commit
d59e0a19bf
@ -104,7 +104,7 @@
|
|||||||
_ (if (empty? path)
|
_ (if (empty? path)
|
||||||
(error "re-frame: \"path\" middleware given no params."))
|
(error "re-frame: \"path\" middleware given no params."))
|
||||||
_ (if (fn? (first args))
|
_ (if (fn? (first args))
|
||||||
(error "re-frame: you've used \"path\" incorrectly. It is a middleare factory and must be called like this \"(path something)\", whereas you just supplied \"path\"."))]
|
(error "re-frame: you've used \"path\" incorrectly. It is a middleware factory and must be called like this \"(path something)\", whereas you just supplied \"path\"."))]
|
||||||
(fn path-middleware
|
(fn path-middleware
|
||||||
[handler]
|
[handler]
|
||||||
(fn path-handler
|
(fn path-handler
|
||||||
|
@ -10,13 +10,13 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn clear-handlers!
|
(defn clear-handlers!
|
||||||
"Unregister all subscription handlers"
|
"Unregisters all subscription handlers"
|
||||||
[]
|
[]
|
||||||
(reset! key->fn {}))
|
(reset! key->fn {}))
|
||||||
|
|
||||||
|
|
||||||
(defn register
|
(defn register
|
||||||
"register a hander function for an id"
|
"Registers a handler function for an id"
|
||||||
[key-v handler-fn]
|
[key-v handler-fn]
|
||||||
(if (contains? @key->fn key-v)
|
(if (contains? @key->fn key-v)
|
||||||
(warn "re-frame: overwriting subscription-handler for: " key-v)) ;; allow it, but warn.
|
(warn "re-frame: overwriting subscription-handler for: " key-v)) ;; allow it, but warn.
|
||||||
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn subscribe
|
(defn subscribe
|
||||||
"returns a reagent/reaction which observes a part of app-db"
|
"Returns a reagent/reaction which observes a part of app-db"
|
||||||
[v]
|
[v]
|
||||||
(let [key-v (first-in-vector v)
|
(let [key-v (first-in-vector v)
|
||||||
handler-fn (get @key->fn key-v)]
|
handler-fn (get @key->fn key-v)]
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
(ns re-frame.undo
|
(ns re-frame.undo
|
||||||
(:require-macros [reagent.ratom :refer [reaction]])
|
(:require-macros [reagent.ratom :refer [reaction]])
|
||||||
(:require
|
(:require
|
||||||
[re-frame.utils :refer [warn]]
|
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
|
[re-frame.utils :refer [warn]]
|
||||||
[re-frame.db :refer [app-db]]
|
[re-frame.db :refer [app-db]]
|
||||||
[re-frame.handlers :as handlers]
|
[re-frame.handlers :as handlers]
|
||||||
[re-frame.subs :as subs]))
|
[re-frame.subs :as subs]))
|
||||||
@ -11,24 +11,24 @@
|
|||||||
;; -- History -------------------------------------------------------------------------------------
|
;; -- History -------------------------------------------------------------------------------------
|
||||||
;;
|
;;
|
||||||
;;
|
;;
|
||||||
(def ^:private max-undos (atom 50)) ;; maximum number of undo states maintained
|
(def ^:private max-undos "Maximum number of undo states maintained" (atom 50))
|
||||||
(defn set-max-undos!
|
(defn set-max-undos!
|
||||||
[n]
|
[n]
|
||||||
(reset! max-undos n))
|
(reset! max-undos n))
|
||||||
|
|
||||||
|
|
||||||
(def ^:private undo-list (reagent/atom [])) ;; a list of history states
|
(def ^:private undo-list "A list of history states" (reagent/atom []))
|
||||||
(def ^:private redo-list (reagent/atom [])) ;; a list of future states, caused by undoing
|
(def ^:private redo-list "A list of future states, caused by undoing" (reagent/atom []))
|
||||||
|
|
||||||
;; -- Explainations -----------------------------------------------------------
|
;; -- Explanations -----------------------------------------------------------
|
||||||
;;
|
;;
|
||||||
;; Each undo has an associated explanation which can be displayed to the user.
|
;; Each undo has an associated explanation which can be displayed to the user.
|
||||||
;;
|
;;
|
||||||
;; Seems really ugly to have mirrored vectors, but ...
|
;; Seems really ugly to have mirrored vectors, but ...
|
||||||
;; the code kinda falls out when you do. I'm feeling lazy.
|
;; the code kinda falls out when you do. I'm feeling lazy.
|
||||||
(def ^:private app-explain (reagent/atom "")) ;; mirrors app-db
|
(def ^:private app-explain "Mirrors app-db" (reagent/atom ""))
|
||||||
(def ^:private undo-explain-list (reagent/atom [])) ;; mirrors undo-list
|
(def ^:private undo-explain-list "Mirrors undo-list" (reagent/atom []))
|
||||||
(def ^:private redo-explain-list (reagent/atom [])) ;; mirrors redo-list
|
(def ^:private redo-explain-list "Mirrors redo-list" (reagent/atom []))
|
||||||
|
|
||||||
(defn- clear-undos!
|
(defn- clear-undos!
|
||||||
[]
|
[]
|
||||||
@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn store-now!
|
(defn store-now!
|
||||||
"stores the value currently in app-db, so the user can later undo"
|
"Stores the value currently in app-db, so the user can later undo"
|
||||||
[explanation]
|
[explanation]
|
||||||
(clear-redos!)
|
(clear-redos!)
|
||||||
(reset! undo-list (vec (take
|
(reset! undo-list (vec (take
|
||||||
@ -63,15 +63,17 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn undos?
|
(defn undos?
|
||||||
|
"Returns true if undos exist, false otherwise"
|
||||||
[]
|
[]
|
||||||
(pos? (count @undo-list)))
|
(pos? (count @undo-list)))
|
||||||
|
|
||||||
(defn redos?
|
(defn redos?
|
||||||
|
"Returns true if redos exist, false otherwise"
|
||||||
[]
|
[]
|
||||||
(pos? (count @redo-list)))
|
(pos? (count @redo-list)))
|
||||||
|
|
||||||
(defn undo-explanations
|
(defn undo-explanations
|
||||||
"return list of undo descriptions or empty list if no undos"
|
"Returns list of undo descriptions or empty list if no undos"
|
||||||
[]
|
[]
|
||||||
(if (undos?)
|
(if (undos?)
|
||||||
(conj @undo-explain-list @app-explain)
|
(conj @undo-explain-list @app-explain)
|
||||||
@ -120,7 +122,7 @@
|
|||||||
(reset! undos (pop u))))
|
(reset! undos (pop u))))
|
||||||
|
|
||||||
(defn- undo-n
|
(defn- undo-n
|
||||||
"undo until we reach n or run out of undos"
|
"undo n steps or until we run out of undos"
|
||||||
[n]
|
[n]
|
||||||
(when (and (pos? n) (undos?))
|
(when (and (pos? n) (undos?))
|
||||||
(undo undo-list app-db redo-list)
|
(undo undo-list app-db redo-list)
|
||||||
@ -145,7 +147,7 @@
|
|||||||
(reset! undos u)))
|
(reset! undos u)))
|
||||||
|
|
||||||
(defn- redo-n
|
(defn- redo-n
|
||||||
"redo until we reach n or run out of redos"
|
"redo n steps or until we run out of redos"
|
||||||
[n]
|
[n]
|
||||||
(when (and (pos? n) (redos?))
|
(when (and (pos? n) (redos?))
|
||||||
(redo undo-list app-db redo-list)
|
(redo undo-list app-db redo-list)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user