From a70ebcab44ff9dd450747bce793fb755316f5903 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 19 Mar 2016 14:53:51 +0200 Subject: [PATCH] Add default error handler for watch and update events on rstore. --- src/uxbox/rstore.cljs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/uxbox/rstore.cljs b/src/uxbox/rstore.cljs index 3e9b10bed..abc469e85 100644 --- a/src/uxbox/rstore.cljs +++ b/src/uxbox/rstore.cljs @@ -86,6 +86,12 @@ (enable-console-print!) +(defn- on-error + "A default error handler." + [e] + (println "Unexpected error: " e) + (rx/empty)) + (defn init "Initializes the stream event loop and return a stream with model changes." @@ -95,6 +101,7 @@ update-s (rx/filter update? stream) state-s (->> update-s (rx/scan #(-apply-update %2 %1) state) + (rx/catch on-error) (rx/share))] ;; Process event sources: combine with the latest model and the result will be @@ -102,6 +109,7 @@ (as-> watch-s $ (rx/with-latest-from vector state-s $) (rx/flat-map (fn [[event model]] (-apply-watch event model stream)) $) + (rx/catch on-error $) (rx/on-value $ emit!)) ;; Process effects: combine with the latest model to process the new effect