Merge branch 'feature/augment-undo' into develop

This commit is contained in:
mike-thompson-day8 2015-04-24 23:48:24 +10:00
commit a9e0c053d4
5 changed files with 37 additions and 14 deletions

View File

@ -1,3 +1,8 @@
## v0.4.0 (2015-04-24)
Improvements:
- #52 Add a way to purge redos
## v0.3.2 (2015-04-21)

View File

@ -1,9 +1,9 @@
(defproject simple-re-frame "0.3.2"
(defproject simple-re-frame "0.4.0.SNAPSHOT"
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-3208"]
[reagent "0.5.0"]
[re-frame "0.3.2"]
[re-frame "0.4.0.SNAPSHOT"]
[figwheel "0.2.6"]]
:plugins [[lein-cljsbuild "1.0.5"]

View File

@ -1,8 +1,8 @@
(defproject todomvc-re-frame "0.3.2"
(defproject todomvc-re-frame "0.4.0.SNAPSHOT"
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-3208"]
[reagent "0.5.0"]
[re-frame "0.3.2"]
[re-frame "0.4.0.SNAPSHOT"]
[secretary "1.2.3"]]
:plugins [[lein-cljsbuild "1.0.5"]]

View File

@ -1,9 +1,9 @@
(defproject re-frame "0.3.2"
(defproject re-frame "0.4.0.SNAPSHOT"
:description "A Clojurescript MVC-like Framework For Writing SPAs Using Regent."
:url "https://github.com/Day8/re-frame.git"
:license {:name "MIT"}
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-3208"]
[org.clojure/clojurescript "0.0-3211"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
[reagent "0.5.0"]]

View File

@ -30,21 +30,29 @@
(def ^:private undo-explain-list (reagent/atom [])) ;; mirrors undo-list
(def ^:private redo-explain-list (reagent/atom [])) ;; mirrors redo-list
(defn- clear-undos!
[]
(reset! undo-list [])
(reset! undo-explain-list []))
(defn- clear-redos!
[]
(reset! redo-list [])
(reset! redo-explain-list []))
(defn clear-history!
[]
(reset! undo-list [])
(reset! redo-list [])
(reset! undo-explain-list [])
(reset! redo-explain-list [])
(clear-undos!)
(clear-redos!)
(reset! app-explain ""))
(defn store-now!
"stores the value currently in app-db, so the user can later undo"
[explanation]
(reset! redo-list []) ;; clear and redo state created by previous undos
(reset! redo-explain-list []) ;; clear and redo state created by previous undos
(clear-redos!)
(reset! undo-list (vec (take
@max-undos
(conj @undo-list @app-db))))
@ -53,6 +61,7 @@
(conj @undo-explain-list @app-explain))))
(reset! app-explain explanation))
(defn undos?
[]
(pos? (count @undo-list)))
@ -119,9 +128,9 @@
(recur (dec n))))
(handlers/register-base ;; not a pure handler
:undo ;; usage: (dispatch [:undo n])
:undo ;; usage: (dispatch [:undo n]) n is optional, defaults to 1
(fn handler
[_ [_ n]] ;; if n absent, defaults to 1
[_ [_ n]]
(if-not (undos?)
(warn "re-frame: you did a (dispatch [:undo]), but there is nothing to undo.")
(undo-n (or n 1)))))
@ -151,3 +160,12 @@
(warn "re-frame: you did a (dispatch [:redo]), but there is nothing to redo.")
(redo-n (or n 1)))))
(handlers/register-base ;; not a pure handler
:purge-redos ;; usage: (dispatch [:purge-redo])
(fn handler
[_ _]
(if-not (redos?)
(warn "re-frame: you did a (dispatch [:purge-redos]), but there is nothing to redo.")
(clear-redos!))))