diff --git a/CHANGES.md b/CHANGES.md index b16ec3a..8dd8f58 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/src/re_frame/std_interceptors.cljc b/src/re_frame/std_interceptors.cljc index c029220..64b260f 100644 --- a/src/re_frame/std_interceptors.cljc +++ b/src/re_frame/std_interceptors.cljc @@ -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? diff --git a/test/re-frame/interceptor_test.cljs b/test/re-frame/interceptor_test.cljs index 4ebfc07..c1cc75d 100644 --- a/test/re-frame/interceptor_test.cljs +++ b/test/re-frame/interceptor_test.cljs @@ -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"