Simplify history handling

This commit is contained in:
Dan Holmsand 2015-09-15 11:57:12 +02:00
parent 2cb96ca5d2
commit a8c86f4f1f
1 changed files with 11 additions and 8 deletions

View File

@ -61,11 +61,11 @@
(assoc state :page-name x))
:goto-page (do
(assert (string? x))
(if history
(do (.setToken history x)
(r/next-tick #(set! js/document.body.scrollTop 0))
state)
(recur state [:set-page x])))))
(when-some [h history]
(.setToken h x)
(r/next-tick #(set! js/document.body.scrollTop 0))
state)
(recur state [:set-page x]))))
(defn dispatch [event]
;; (dbg event)
@ -98,10 +98,13 @@
(re-pattern (str page "$")) "")
(string/replace #"/*$" ""))))
(History.)))
(evt/listen hevt/NAVIGATE #(dispatch [:set-page (.-token %)]))
(evt/listen hevt/NAVIGATE #(when (.-isNavigation %)
(dispatch [:set-page (.-token %)])))
(.setEnabled true))
(when (and page (not html5) (-> history .getToken empty?))
(.setToken history page)))))
(let [p (if (and page (not html5) (-> history .getToken empty?))
page
(.getToken history))]
(dispatch [:set-page p])))))
(defn to-relative [f]
(string/replace f #"^/" ""))