From 06f7a29583d652038b963860e559a1500ee15036 Mon Sep 17 00:00:00 2001 From: hipitihop Date: Thu, 23 Apr 2015 15:44:57 +1000 Subject: [PATCH 1/5] undo - add optional parameter clear-redos? to :undo handler. Defaults to false so this is backward compatible. --- src/re_frame/undo.cljs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/re_frame/undo.cljs b/src/re_frame/undo.cljs index a02e708..163bfab 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))) @@ -121,10 +130,13 @@ (handlers/register-base ;; not a pure handler :undo ;; usage: (dispatch [:undo n]) (fn handler - [_ [_ n]] ;; if n absent, defaults to 1 + [_ [_ n clear-redos?]] + ;; if n absent, defaults to 1. If clear-redos? absent, defaults to false. (if-not (undos?) (warn "re-frame: you did a (dispatch [:undo]), but there is nothing to undo.") - (undo-n (or n 1))))) + (do + (undo-n (or n 1)) + (when clear-redos? (clear-redos!)))))) (defn- redo From 2571cb5e0bbc65dab3cca86f204ca4bd97cd54dd Mon Sep 17 00:00:00 2001 From: hipitihop Date: Fri, 24 Apr 2015 16:12:14 +1000 Subject: [PATCH 2/5] undo - change undo to support separate event :purge-redos - bump to [org.clojure/clojurescript "0.0-3211"] --- CHANGES.md | 5 +++++ project.clj | 4 ++-- src/re_frame/undo.cljs | 15 +++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1dd8818..4a94254 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +## v0.4.0 (2015-04-24) + +Improvements: + - new handler :purge-redos in core.undo + - move to clojurescript v0.0-3211 ## v0.3.2 (2015-04-21) diff --git a/project.clj b/project.clj index fe8418c..24adee8 100644 --- a/project.clj +++ b/project.clj @@ -1,9 +1,9 @@ -(defproject re-frame "0.3.2" +(defproject re-frame "0.4.0" :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 163bfab..b5939ac 100644 --- a/src/re_frame/undo.cljs +++ b/src/re_frame/undo.cljs @@ -130,13 +130,11 @@ (handlers/register-base ;; not a pure handler :undo ;; usage: (dispatch [:undo n]) (fn handler - [_ [_ n clear-redos?]] + [_ [_ n]] ;; if n absent, defaults to 1. If clear-redos? absent, defaults to false. (if-not (undos?) (warn "re-frame: you did a (dispatch [:undo]), but there is nothing to undo.") - (do - (undo-n (or n 1)) - (when clear-redos? (clear-redos!)))))) + (undo-n (or n 1))))) (defn- redo @@ -163,3 +161,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!)))) + From 0a335f4871711da1c0091dfede2750feaef80bfd Mon Sep 17 00:00:00 2001 From: mike-thompson-day8 Date: Fri, 24 Apr 2015 22:16:04 +1000 Subject: [PATCH 3/5] version 0.4.0.SNAPSHOT --- examples/simple/project.clj | 4 ++-- examples/todomvc/project.clj | 4 ++-- project.clj | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) 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 24adee8..5282698 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject re-frame "0.4.0" +(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"} From edc5a85780457b14c80c190e1757c5081269108e Mon Sep 17 00:00:00 2001 From: mike-thompson-day8 Date: Fri, 24 Apr 2015 22:17:43 +1000 Subject: [PATCH 4/5] Links changes with issue --- CHANGES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4a94254..7d50eee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,8 +1,8 @@ ## v0.4.0 (2015-04-24) Improvements: - - new handler :purge-redos in core.undo - - move to clojurescript v0.0-3211 + - #52 Add a way to purge redos + ## v0.3.2 (2015-04-21) From e80c6c94b38df7823de465cb9d68f04f18f2e56a Mon Sep 17 00:00:00 2001 From: mike-thompson-day8 Date: Fri, 24 Apr 2015 23:46:27 +1000 Subject: [PATCH 5/5] Improve comment --- src/re_frame/undo.cljs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/re_frame/undo.cljs b/src/re_frame/undo.cljs index b5939ac..15d36b3 100644 --- a/src/re_frame/undo.cljs +++ b/src/re_frame/undo.cljs @@ -128,10 +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. If clear-redos? absent, defaults to false. (if-not (undos?) (warn "re-frame: you did a (dispatch [:undo]), but there is nothing to undo.") (undo-n (or n 1)))))