mirror of
https://github.com/penpot/penpot.git
synced 2025-07-26 19:07:20 +02:00
🎉 Add proper error boundaries for main component.
This commit is contained in:
parent
4c36bce5bd
commit
8cb84d2911
3 changed files with 59 additions and 2 deletions
50
frontend/src/uxbox/main/ui/components/error.cljs
Normal file
50
frontend/src/uxbox/main/ui/components/error.cljs
Normal file
|
@ -0,0 +1,50 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs S.L
|
||||
|
||||
(ns uxbox.main.ui.components.error
|
||||
"A hight order component for error handling."
|
||||
(:require
|
||||
[beicon.core :as rx]
|
||||
[goog.object :as gobj]
|
||||
[rumext.alpha :as mf]))
|
||||
|
||||
(defn wrap-catch
|
||||
[component {:keys [fallback on-error]}]
|
||||
(let [constructor
|
||||
(fn [props]
|
||||
(this-as this
|
||||
(unchecked-set this "state" #js {})
|
||||
(.call js/React.Component this props)))
|
||||
|
||||
did-catch
|
||||
(fn [error info]
|
||||
(when (fn? on-error)
|
||||
(on-error error info)))
|
||||
|
||||
derive-state
|
||||
(fn [error]
|
||||
#js {:error error})
|
||||
|
||||
render
|
||||
(fn []
|
||||
(this-as this
|
||||
(let [state (gobj/get this "state")
|
||||
error (gobj/get state "error")]
|
||||
(if error
|
||||
(mf/element fallback #js {:error error})
|
||||
(mf/element component #js {})))))
|
||||
|
||||
_ (goog/inherits constructor js/React.Component)
|
||||
prototype (unchecked-get constructor "prototype")]
|
||||
|
||||
(unchecked-set constructor "displayName" "ErrorBoundary")
|
||||
(unchecked-set constructor "getDerivedStateFromError" derive-state)
|
||||
(unchecked-set prototype "componentDidCatch" did-catch)
|
||||
(unchecked-set prototype "render" render)
|
||||
constructor))
|
Loading…
Add table
Add a link
Reference in a new issue