From 2a8c1d5f03ea94ca9634986329451580a00b420f Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 24 Jul 2019 11:34:15 +0200 Subject: [PATCH] :recycle: Refactor application initialization. Fixes some bugs on development enviroment that causes two apps loading together. --- frontend/src/uxbox/main.cljs | 10 +++++++--- frontend/src/uxbox/view.cljs | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/frontend/src/uxbox/main.cljs b/frontend/src/uxbox/main.cljs index 0571d053b..4089b7ccd 100644 --- a/frontend/src/uxbox/main.cljs +++ b/frontend/src/uxbox/main.cljs @@ -42,13 +42,13 @@ (defn- on-navigate [router path] (let [match (rt/match router path)] - ;; (prn "on-navigate" path match) + (prn "main$on-navigate" path) (cond #_(and (= path "") (nil? match)) #_(html-history/set-path! "/dashboard/projects") (nil? match) - (prn "TODO 404") + (prn "TODO 404 main") :else (st/emit! #(assoc % :route match))))) @@ -70,8 +70,11 @@ (on-navigate router cpath))) +(def app-sym (.for js/Symbol "uxbox.app")) + (defn ^:export init [] + (unchecked-set js/window app-sym "main") (st/init) (init-ui)) @@ -85,4 +88,5 @@ (defn ^:after-load after-load [] - (reinit)) + (when (= "main" (unchecked-get js/window app-sym)) + (reinit))) diff --git a/frontend/src/uxbox/view.cljs b/frontend/src/uxbox/view.cljs index 8935f8921..16b3d4859 100644 --- a/frontend/src/uxbox/view.cljs +++ b/frontend/src/uxbox/view.cljs @@ -59,13 +59,10 @@ (defn- on-navigate [router path] (let [match (rt/match router path)] - (prn "on-navigate" path match) + (prn "view$on-navigate" path) (cond - ;; (and (= path "") (nil? match)) - ;; (html-history/set-path! "/not-found") - (nil? match) - (prn "TODO 404") + (prn "TODO 404 view" match) :else (st/emit! #(assoc % :route match))))) @@ -84,21 +81,25 @@ (on-navigate router cpath))) +(def app-sym (.for js/Symbol "uxbox.app")) + (defn ^:export init [] + (unchecked-set js/window app-sym "view") (st/init) (init-ui)) (defn reinit [] (remove-watch html-history/path ::view) - (.unmountComponentAtNode js/ReactDOM (dom/get-element "app")) - (.unmountComponentAtNode js/ReactDOM (dom/get-element "lightbox")) - (.unmountComponentAtNode js/ReactDOM (dom/get-element "loader")) + (mf/unmount (dom/get-element "app")) + (mf/unmount (dom/get-element "lightbox")) + (mf/unmount (dom/get-element "loader")) (init-ui)) (defn ^:after-load after-load [] - (reinit)) + (when (= "view" (unchecked-get js/window app-sym)) + (reinit)))