rswap! always reutrns nil

This commit is contained in:
Dan Holmsand 2015-09-09 11:46:41 +02:00
parent 47a0d80a70
commit 7284460ef7
1 changed files with 20 additions and 20 deletions

View File

@ -13,22 +13,23 @@
(enable-console-print!)) (enable-console-print!))
(defn rswap! [a f & args] (defn rswap! [a f & args]
;; Like swap!, except that recursive swaps on the same atom are ok. ;; Like swap!, except that recursive swaps on the same atom are ok,
;; and always returns nil.
{:pre [(satisfies? ISwap a) {:pre [(satisfies? ISwap a)
(ifn? f)]} (ifn? f)]}
(if a.rswapping (if a.rswapping
(do (-> (or a.rswapfs (-> (or a.rswapfs
(set! a.rswapfs (array))) (set! a.rswapfs (array)))
(.push #(apply f % args))) (.push #(apply f % args)))
(swap! a identity))
(do (set! a.rswapping true) (do (set! a.rswapping true)
(try (swap! a (fn [state] (try (swap! a (fn [state]
(loop [s (apply f state args)] (loop [s (apply f state args)]
(if-some [sf (some-> a .-rswapfs .shift)] (if-some [sf (some-> a.rswapfs .shift)]
(recur (sf s)) (recur (sf s))
s)))) s))))
(finally (finally
(set! a.rswapping false)))))) (set! a.rswapping false)))))
nil)
;;; Configuration ;;; Configuration
@ -54,27 +55,26 @@
(str (:default-title state)))] (str (:default-title state)))]
(assert (vector? v1)) (assert (vector? v1))
(when r/is-client (when r/is-client
(r/next-tick #(set! js/document.title title))) (set! js/document.title title))
(assoc state :main-content v1 :title title)) (assoc state :main-content v1 :title title))
:set-page (do (assert (string? v1)) :set-page (do (assert (string? v1))
(secretary/dispatch! v1) (secretary/dispatch! v1)
(assoc state :page-name v1)) (assoc state :page-name v1))
:goto-page (do :goto-page (do
(assert (string? v1)) (assert (string? v1))
(when r/is-client (if r/is-client
(.setToken history v1 false) (do (.setToken history v1)
(r/next-tick #(set! js/document.body.scrollTop 0))) (r/next-tick #(set! js/document.body.scrollTop 0))
(recur state [:set-page v1])) state)
(recur state [:set-page v1])))
state)) state))
(defn dispatch [event] (defn dispatch [event]
;; (dbg event) ;; (dbg event)
(rswap! config demo-handler event) (rswap! config demo-handler event))
nil)
(defn add-page-to-generate [url] (defn add-page-to-generate [url]
{:pre [(string? url)] {:pre [(string? url)]}
:post [(map? %)]}
(swap! config update-in [:pages] conj url)) (swap! config update-in [:pages] conj url))
(defn register-page [url comp title] (defn register-page [url comp title]
@ -208,7 +208,7 @@
(when r/is-client (when r/is-client
(let [page-conf (when (exists? js/pageConfig) (let [page-conf (when (exists? js/pageConfig)
(js->clj js/pageConfig :keywordize-keys true)) (js->clj js/pageConfig :keywordize-keys true))
conf (swap! config merge page-conf)] conf (swap! config merge page-conf)
(init-history (:page-name conf)) {:keys [page-name body main-div]} conf]
(r/render-component (:body conf) (init-history page-name)
(js/document.getElementById (:main-div conf)))))) (r/render-component body (js/document.getElementById main-div)))))