Clean re-frame example initialization

This commit is contained in:
Juho Teperi 2020-09-23 13:12:00 +03:00
parent 208eeeb5c5
commit dea8894610
3 changed files with 9 additions and 11 deletions

View file

@ -33,7 +33,7 @@
{:builds {:builds
[{:id "dev" [{:id "dev"
:source-paths ["src/cljs"] :source-paths ["src/cljs"]
:figwheel {:on-jsload "frontend-re-frame.core/mount-root"} :figwheel true
:compiler {:main frontend-re-frame.core :compiler {:main frontend-re-frame.core
:output-to "resources/public/js/compiled/app.js" :output-to "resources/public/js/compiled/app.js"
:output-dir "resources/public/js/compiled/out" :output-dir "resources/public/js/compiled/out"

View file

@ -2,12 +2,9 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset='utf-8'> <meta charset='utf-8'>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="js/compiled/app.js"></script> <script src="js/compiled/app.js"></script>
<script>frontend_re_frame.core.init();</script>
</body> </body>
</html> </html>

View file

@ -11,8 +11,10 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::initialize-db ::initialize-db
(fn [_ _] (fn [db _]
{:current-route nil})) (if db
db
{:current-route nil})))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::navigate ::navigate
@ -141,13 +143,12 @@
(enable-console-print!) (enable-console-print!)
(println "dev mode"))) (println "dev mode")))
(defn mount-root [] (defn init []
(re-frame/clear-subscription-cache!) (re-frame/clear-subscription-cache!)
(re-frame/dispatch-sync [::initialize-db])
(dev-setup)
(init-routes!) ;; Reset routes on figwheel reload (init-routes!) ;; Reset routes on figwheel reload
(reagent/render [router-component {:router router}] (reagent/render [router-component {:router router}]
(.getElementById js/document "app"))) (.getElementById js/document "app")))
(defn ^:export init [] (init)
(re-frame/dispatch-sync [::initialize-db])
(dev-setup)
(mount-root))