From 5034ad8b17b0a27736943b81c46495afe117f1b6 Mon Sep 17 00:00:00 2001 From: Oliver George Date: Fri, 10 Jul 2020 12:35:03 +1000 Subject: [PATCH] Repro for reframe issue: Improve exception handing associated with subs https://github.com/day8/re-frame/issues/633 --- deps.edn | 3 ++- src/hello_world/core.cljs | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/deps.edn b/deps.edn index 66bb929..3e35e3e 100644 --- a/deps.edn +++ b/deps.edn @@ -1 +1,2 @@ -{:deps {org.clojure/clojurescript {:mvn/version "1.10.758"}}} +{:deps {org.clojure/clojurescript {:mvn/version "1.10.758"} + re-frame {:mvn/version "0.12.0"}}} diff --git a/src/hello_world/core.cljs b/src/hello_world/core.cljs index fae98c0..a08e100 100644 --- a/src/hello_world/core.cljs +++ b/src/hello_world/core.cljs @@ -1,3 +1,22 @@ -(ns hello-world.core) +(ns hello-world.core + (:require [reagent.core :as r] + [reagent.dom :as rdom] + [re-frame.core :as rf])) -(println "Hello world!") +(rf/reg-sub + ::throwing-sub + (fn [_ _] + (assert (odd? 2)) + "fn sub")) + +(defn app [] + [:p @(rf/subscribe [::throwing-sub])]) + +(defn error-boundary [] + (let [*error (r/atom nil)] + (r/create-class + {:get-derived-state-from-error (fn [e] (reset! *error e)) + :component-did-catch (fn [_ _ _] true) + :reagent-render (fn [form] (if @*error [:div (str @*error)] form))}))) + +(rdom/render [error-boundary [app]] (js/document.getElementById "app"))