Skip to content

Commit

Permalink
mark side-effecting functions as such
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Aug 19, 2015
1 parent dc82af6 commit 6ad431f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/re_frame/frame.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ by the process doing actual transduction. See event processing helpers below for
xform (get-frame-transducer frame last)]
(transduce xform reducing-fn [init-db] events)))

(defn process-event-on-atom [frame db-atom event]
(defn process-event-on-atom! [frame db-atom event]
(let [new-db (process-event frame @db-atom event)]
(reset-if-changed! db-atom new-db)))

(defn process-events-on-atom [frame db-atom events]
(defn process-events-on-atom! [frame db-atom events]
(let [reducing-fn (fn
([db-atom] db-atom) ; completion
([db-atom new-db] ; in each step
Expand All @@ -150,7 +150,7 @@ by the process doing actual transduction. See event processing helpers below for
xform (get-frame-transducer frame deref)]
(transduce xform reducing-fn db-atom events)))

(defn process-events-on-atom-with-coallesced-write [frame db-atom events]
(defn process-events-on-atom-with-coallesced-write! [frame db-atom events]
(let [reducing-fn (fn
([final-db] ; completion
(reset-if-changed! db-atom final-db)) ; commit final-db to atom
Expand Down
4 changes: 2 additions & 2 deletions src/re_frame/scaffold.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
(do (reagent/flush) (<! (timeout 20))) ;; wait just over one annimation frame (16ms), to rensure all pending GUI work is flushed to the DOM.
(<! (timeout 0)))] ;; just in case we are handling one dispatch after an other, give the browser back control to do its stuff
(try
(frame/process-event-on-atom @frame-atom db-atom event)
(frame/process-event-on-atom! @frame-atom db-atom event)

;; If the handler throws:
;; - allow the exception to bubble up because the app, in production,
Expand Down Expand Up @@ -158,7 +158,7 @@
Usage example:
(dispatch-sync [:delete-item 42])"
[db-atom frame-atom event]
(frame/process-event-on-atom @frame-atom db-atom event)
(frame/process-event-on-atom! @frame-atom db-atom event)
nil) ;; Ensure nil return. See https://github.com/Day8/re-frame/wiki/Beware-Returning-False

(def dispatch-sync (partial dispatch-sync* app-db app-frame))
6 changes: 3 additions & 3 deletions test/re_frame/test/frame.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
add-handler (fn [state [_event-id num]] (+ state num))
frame (-> (make-test-frame-with-log-recording)
(frame/register-event-handler :add add-handler))]
(frame/process-event-on-atom frame db [:add 100])
(frame/process-event-on-atom! frame db [:add 100])
(is (= @db 100))
(is (= @reset-counter 1))))
(testing "process multiple events on atom"
Expand All @@ -112,7 +112,7 @@
add-handler (fn [state [_event-id num]] (+ state num))
frame (-> (make-test-frame-with-log-recording)
(frame/register-event-handler :add add-handler))]
(frame/process-events-on-atom frame db [[:add 1] [:add 2]])
(frame/process-events-on-atom! frame db [[:add 1] [:add 2]])
(is (= @db 3))
(is (= @reset-counter 2))))
(testing "process multiple events on atom with coallesced write"
Expand All @@ -122,7 +122,7 @@
add-handler (fn [state [_event-id num]] (+ state num))
frame (-> (make-test-frame-with-log-recording)
(frame/register-event-handler :add add-handler))]
(frame/process-events-on-atom-with-coallesced-write frame db [[:add 1] [:add 2]])
(frame/process-events-on-atom-with-coallesced-write! frame db [[:add 1] [:add 2]])
(is (= @db 3))
(is (= @reset-counter 1)))))

Expand Down

0 comments on commit 6ad431f

Please sign in to comment.