mirror of https://github.com/status-im/reagent.git
wip
This commit is contained in:
parent
b520dfd6be
commit
df464eda35
|
@ -20,18 +20,19 @@
|
||||||
:alt "Fork me on GitHub"
|
:alt "Fork me on GitHub"
|
||||||
:src "https://s3.amazonaws.com/github/ribbons/forkme_left_orange_ff7600.png"}]])
|
:src "https://s3.amazonaws.com/github/ribbons/forkme_left_orange_ff7600.png"}]])
|
||||||
|
|
||||||
(def index-page "index.html")
|
;; (def index-page "index.html")
|
||||||
(def news-page "news/index.html")
|
;; (def news-page "news/index.html")
|
||||||
|
|
||||||
(tools/register-page index-page [#'intro/main]
|
;; (tools/register-page index-page [#'intro/main]
|
||||||
"Reagent: Minimalistic React for ClojureScript")
|
;; "Reagent: Minimalistic React for ClojureScript")
|
||||||
(tools/register-page news-page [#'news/main]
|
;; (tools/register-page news-page [#'news/main]
|
||||||
"Reagent news")
|
;; "Reagent news")
|
||||||
|
|
||||||
|
(defroute "/" [] (dispatch [:content [#'intro/main]]))
|
||||||
(defroute main-page "/index.html" [] (dispatch [:content [#'intro/main]]))
|
(defroute main-page "/index.html" [] (dispatch [:content [#'intro/main]]))
|
||||||
(defroute news-p "/news/index.html" [] (dispatch [:content [#'news/main]]))
|
(defroute news-page "/news/index.html" [] (dispatch [:content [#'news/main]]))
|
||||||
(tools/reg-page (main-page))
|
(tools/reg-page (main-page))
|
||||||
(tools/reg-page (news-p))
|
(tools/reg-page (news-page))
|
||||||
|
|
||||||
(defn demo []
|
(defn demo []
|
||||||
[:div
|
[:div
|
||||||
|
@ -39,7 +40,7 @@
|
||||||
[:ul.nav
|
[:ul.nav
|
||||||
[:li.brand [link {:href (main-page)} "Reagent:"]]
|
[:li.brand [link {:href (main-page)} "Reagent:"]]
|
||||||
[:li [link {:href (main-page)} "Intro"]]
|
[:li [link {:href (main-page)} "Intro"]]
|
||||||
[:li [link {:href (news-p)} "News"]]
|
[:li [link {:href (news-page)} "News"]]
|
||||||
[:li [:a github "GitHub"]]]]
|
[:li [:a github "GitHub"]]]]
|
||||||
@test-results
|
@test-results
|
||||||
[tools/page-content]
|
[tools/page-content]
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
(def title "News in 0.5.0")
|
(def title "News in 0.5.0")
|
||||||
|
|
||||||
(declare main)
|
(declare main)
|
||||||
(defroute path "/news/news050.html" [] (dispatch [:content [#'main]]))
|
(defroute path "/news/news050.html" [] (dispatch [:content [#'main] title]))
|
||||||
(tools/reg-page (path))
|
(tools/reg-page (path))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,19 +16,20 @@
|
||||||
(declare page-content)
|
(declare page-content)
|
||||||
|
|
||||||
(defn rswap! [a f & args]
|
(defn rswap! [a f & args]
|
||||||
;; Like swap!, except that recursive swaps are ok
|
;; Roughly like swap!, except that recursive swaps are ok
|
||||||
(let [fs (if-some [arr (.-rswapfs a)]
|
(let [fs (if-some [arr (.-rswapfs a)]
|
||||||
arr
|
arr
|
||||||
(set! (.-rswapfs a) (array)))]
|
(set! (.-rswapfs a) (array)))]
|
||||||
(.push fs #(apply f % args))
|
(.push fs #(apply f % args))
|
||||||
(if (< 1 (.-length fs))
|
(if (< 1 (.-length fs))
|
||||||
(swap! a identity)
|
nil
|
||||||
(loop []
|
(let [f' (fn [state]
|
||||||
(let [s (swap! a (aget fs 0))]
|
(let [s ((aget fs 0) state)]
|
||||||
(.shift fs)
|
(.shift fs)
|
||||||
(if (-> fs .-length pos?)
|
(if (-> fs .-length pos?)
|
||||||
(recur)
|
(recur s)
|
||||||
s))))))
|
s)))]
|
||||||
|
(swap! a f')))))
|
||||||
|
|
||||||
|
|
||||||
;;; Configuration
|
;;; Configuration
|
||||||
|
@ -44,6 +45,7 @@
|
||||||
:js-file "js/main.js"
|
:js-file "js/main.js"
|
||||||
:js-dir "js/out"
|
:js-dir "js/out"
|
||||||
:main-div "main-content"
|
:main-div "main-content"
|
||||||
|
:default-title "Reagent"
|
||||||
:allow-html5-history false}))
|
:allow-html5-history false}))
|
||||||
|
|
||||||
(defonce page (r/atom "index.html"))
|
(defonce page (r/atom "index.html"))
|
||||||
|
@ -54,17 +56,24 @@
|
||||||
(defn demo-handler [state [id v1 v2 :as event]]
|
(defn demo-handler [state [id v1 v2 :as event]]
|
||||||
(case id
|
(case id
|
||||||
:content (do
|
:content (do
|
||||||
(assoc state :main-content v1))
|
(let [title (or v2 (:default-title @config) "")]
|
||||||
|
(when r/is-client
|
||||||
|
(r/next-tick #(set! js/document.title title)))
|
||||||
|
(assoc state
|
||||||
|
:main-content v1
|
||||||
|
:title title)))
|
||||||
|
:set-page (do (secretary/dispatch! v1)
|
||||||
|
(assoc state :page v1))
|
||||||
:goto-page (do
|
:goto-page (do
|
||||||
(.setToken history v1)
|
(when r/is-client
|
||||||
(assoc state :page v1))
|
(.setToken history v1 false)
|
||||||
|
(r/next-tick #(set! js/document.body.scrollTop 0)))
|
||||||
|
(recur state [:set-page v1 v2]))
|
||||||
state))
|
state))
|
||||||
|
|
||||||
(defn dispatch [event]
|
(defn dispatch [event]
|
||||||
;; (r/next-tick #(rswap! config demo-handler event))
|
|
||||||
(dbg event)
|
(dbg event)
|
||||||
(rswap! config demo-handler event)
|
(rswap! config demo-handler event)
|
||||||
(:main-content @config)
|
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
(defn reg-page [url]
|
(defn reg-page [url]
|
||||||
|
@ -73,7 +82,7 @@
|
||||||
(defn init-history []
|
(defn init-history []
|
||||||
(when-not history
|
(when-not history
|
||||||
(doto (set! history (History.))
|
(doto (set! history (History.))
|
||||||
(evt/listen hevt/NAVIGATE #(secretary/dispatch! (.-token %)))
|
(evt/listen hevt/NAVIGATE #(dispatch [:set-page (.-token %)]))
|
||||||
(.setEnabled true))))
|
(.setEnabled true))))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue