Merge pull request #341 from bradleesand/patch-1

Don't run on-changes if db is not in effects
This commit is contained in:
Mike Thompson 2017-07-16 19:44:39 +10:00 committed by GitHub
commit 4f964b7030
3 changed files with 15 additions and 4 deletions

View File

@ -9,6 +9,8 @@
- [#357](https://github.com/Day8/re-frame/pull/357)
- [#340](https://github.com/Day8/re-frame/pull/340)
- [#341](https://github.com/Day8/re-frame/pull/341) Fix `re-frame.std-interceptors/on-changes` to work even if effect handler does not set `:db`.
## 0.9.4 (2017.06.01)

View File

@ -294,7 +294,9 @@
;; work out if any "inputs" have changed
new-ins (map #(get-in new-db %) in-paths)
old-ins (map #(get-in old-db %) in-paths)
changed-ins? (some false? (map identical? new-ins old-ins))]
;; make sure the db is actually set in the effect
changed-ins? (and (contains? (get-effect context) :db)
(some false? (map identical? new-ins old-ins)))]
;; if one of the inputs has changed, then run 'f'
(if changed-ins?

View File

@ -106,8 +106,6 @@
(get-effect))]
(is (= e {:db 5 :dispatch [:a]}))))
(deftest test-on-changes
(let [change-handler-i (-> (fn [db v] (assoc db :a 10))
db-handler->interceptor)
@ -115,6 +113,9 @@
no-change-handler-i (-> (fn [db v] db)
db-handler->interceptor)
no-db-handler-i (-> (fn [ctx v] {})
fx-handler->interceptor)
change-i (on-changes + [:c] [:a] [:b])
orig-db {:a 0 :b 2}]
@ -127,7 +128,13 @@
(-> (context [] [] orig-db)
((:before change-handler-i)) ;; cause change to :a
((:after change-i))
(get-effect :db))))))
(get-effect :db))))
(is (= ::not-found
(-> (context [] [] orig-db)
((:before no-db-handler-i)) ;; no db effect in context
((:after change-i))
(get-effect :db ::not-found))))))
(deftest test-after
(testing "when no db effect is returned"