Skip to content
This repository has been archived by the owner on Jan 19, 2018. It is now read-only.

Commit

Permalink
prefer *store to ref-store
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jun 18, 2017
1 parent 196e8bb commit 47645a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions ir.edn
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 27,14 @@
"dispatch!"
["op" "op-data"]
["let"
[["next-store" ["updater" "@ref-store" "op" "op-data"]]]
["reset!" "ref-store" "next-store"]]],
[["next-store" ["updater" "@*store" "op" "op-data"]]]
["reset!" "*store" "next-store"]]],
"on-jsload!" ["defn" "reload!" [] ["clear-cache!"] ["render-app!"] ["println" "|Code updated."]],
"render-app!" ["defn"
"render-app!"
[]
["render!" ["comp-container" "@ref-store"] "mount-target" "dispatch!"]],
"ref-store" ["defonce" "ref-store" ["atom" ["{}" [":states" ["{}"]]]]],
["render!" ["comp-container" "@*store"] "mount-target" "dispatch!"]],
"*store" ["defonce" "*store" ["atom" ["{}" [":states" ["{}"]]]]],
"server-rendered?" ["def"
"server-rendered?"
["some?" ["js/document.querySelector" "|meta#server-rendered"]]],
Expand All @@ -45,10 45,10 @@
"server-rendered?"
["falsify-stage!"
"mount-target"
["render-element" ["comp-container" "@ref-store"]]
["render-element" ["comp-container" "@*store"]]
"dispatch!"]]
["render-app!"]
["add-watch" "ref-store" ":changes" "render-app!"]
["add-watch" "*store" ":changes" "render-app!"]
["println" "|App started."]],
"mount-target" ["def" "mount-target" [".querySelector" "js/document" "|.app"]]},
:procs [["set!" [".-onload" "js/window"] "main!"]]},
Expand Down
10 changes: 5 additions & 5 deletions src/app/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 5,24 @@
[cljs.reader :refer [read-string]]
[app.updater.core :refer [updater]]))

(defonce ref-store (atom {:states {}}))
(defonce *store (atom {:states {}}))

(defn dispatch! [op op-data]
(let [next-store (updater @ref-store op op-data)] (reset! ref-store next-store)))
(let [next-store (updater @*store op op-data)] (reset! *store next-store)))

(def mount-target (.querySelector js/document ".app"))

(defn render-app! [] (render! (comp-container @ref-store) mount-target dispatch!))
(defn render-app! [] (render! (comp-container @*store) mount-target dispatch!))

(defn reload! [] (clear-cache!) (render-app!) (println "Code updated."))

(def server-rendered? (some? (js/document.querySelector "meta#server-rendered")))

(defn main! []
(if server-rendered?
(falsify-stage! mount-target (render-element (comp-container @ref-store)) dispatch!))
(falsify-stage! mount-target (render-element (comp-container @*store)) dispatch!))
(render-app!)
(add-watch ref-store :changes render-app!)
(add-watch *store :changes render-app!)
(println "App started."))

(set! (.-onload js/window) main!)

0 comments on commit 47645a7

Please sign in to comment.