 
 (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."

        update-s (rx/filter update? stream)
        state-s (->> update-s
                     (rx/scan #(-apply-update %2 %1) state)
                     (rx/share))]

    ;; Process event sources: combine with the latest model and the result will be

    (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
