diff --git a/CHANGES.md b/CHANGES.md index 1dd8818..7d50eee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +## v0.4.0 (2015-04-24) + +Improvements: + - #52 Add a way to purge redos + ## v0.3.2 (2015-04-21) diff --git a/examples/simple/project.clj b/examples/simple/project.clj index 4bae0b7..a960efb 100644 --- a/examples/simple/project.clj +++ b/examples/simple/project.clj @@ -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"] diff --git a/examples/todomvc/project.clj b/examples/todomvc/project.clj index 1c0ae20..8aea007 100644 --- a/examples/todomvc/project.clj +++ b/examples/todomvc/project.clj @@ -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"]] diff --git a/project.clj b/project.clj index fe8418c..5282698 100644 --- a/project.clj +++ b/project.clj @@ -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"]] diff --git a/src/re_frame/undo.cljs b/src/re_frame/undo.cljs index a02e708..15d36b3 100644 --- a/src/re_frame/undo.cljs +++ b/src/re_frame/undo.cljs @@ -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!)))) +