Skip to content

Commit

Permalink
making trim-v before/after symmetrical
Browse files Browse the repository at this point in the history
  • Loading branch information
oliyh committed Dec 9, 2016
1 parent acdcf54 commit 8958989
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/re_frame/std_interceptors.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@
:id :trim-v
:before (fn trimv-before
[context]
(update-in context [:coeffects :event] subvec 1))))
(-> context
(update-in [:coeffects :event] subvec 1)
(assoc-in [:coeffects ::untrimmed-event] (get-coeffect context :event))))
:after (fn trimv-after
[context]
(-> context
(assoc-in [:coeffects :event] (get-coeffect context ::untrimmed-event))
(update :coeffects dissoc ::untrimmed-event)))))


;; -- Interceptor Factories - PART 1 ---------------------------------------------------------------
Expand Down Expand Up @@ -274,5 +281,3 @@
(assoc-in new-db out-path)
(assoc-effect context :db))
context)))))


12 changes: 6 additions & 6 deletions test/re-frame/interceptor_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
(enable-console-print!)

(deftest test-trim-v
(let [c (-> (context [:a :b :c] [])
((:before trim-v)))]
(let [ctx (context [:a :b :c] [])
c ((:before trim-v) ctx)]
(is (= (get-coeffect c :event)
[:b :c]))))
[:b :c]))

(let [c-after ((:after trim-v) c)]
(is (= c-after ctx)))))


(deftest test-one-level-path
Expand Down Expand Up @@ -114,6 +117,3 @@
((:before change-handler-i)) ;; cause change to :a
((:after change-i))
(get-effect :db))))))



0 comments on commit 8958989

Please sign in to comment.