Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (35 sloc) 1.54 KB
(ns app.main
(:require [respo.core :refer [render! clear-cache! realize-ssr!]]
[app.comp.container :refer [comp-container]]
[app.updater :refer [updater]]
[app.schema :as schema]
[reel.util :refer [listen-devtools!]]
[reel.core :refer [reel-updater refresh-reel]]
[reel.schema :as reel-schema]
[cljs.reader :refer [read-string]]
[app.config :as config]))
(defonce *reel
(atom (-> reel-schema/reel (assoc :base schema/store) (assoc :store schema/store))))
(defn dispatch! [op op-data]
(comment println "Dispatch:" op)
(reset! *reel (reel-updater updater @*reel op op-data)))
(def mount-target (.querySelector js/document ".app"))
(defn persist-storage! []
(.setItem js/localStorage (:storage config/site) (pr-str (:store @*reel))))
(defn render-app! [renderer]
(renderer mount-target (comp-container @*reel) #(dispatch! %1 %2)))
(def ssr? (some? (js/document.querySelector "meta.respo-ssr")))
(defn main! []
(if ssr? (render-app! realize-ssr!))
(render-app! render!)
(add-watch *reel :changes (fn [] (render-app! render!)))
(listen-devtools! "a" dispatch!)
(.addEventListener js/window "beforeunload" persist-storage!)
(js/setInterval persist-storage! (* 1000 60))
(let [raw (.getItem js/localStorage (:storage config/site))]
(when (some? raw) (dispatch! :hydrate-storage (read-string raw))))
(println "App started."))
(defn reload! []
(clear-cache!)
(reset! *reel (refresh-reel @*reel schema/store updater))
(println "Code updated."))