Skip to content

Instantly share code, notes, and snippets.

@shiftb
Forked from danielsz/pushState.cljs
Last active March 6, 2017 19:23
Show Gist options
  • Save shiftb/21a28328f9fb684cfa8a to your computer and use it in GitHub Desktop.
Save shiftb/21a28328f9fb684cfa8a to your computer and use it in GitHub Desktop.
Example using pushState with ClojureScript + Secretary
; require [goog.events :as events]
; import [goog.history Html5History]
; [goog Uri]
; [goog.history EventType]
(defn listen [el type]
(let [out (chan)]
(events/listen el type
(fn [e] (put! out e)))
out))
(def history (Html5History.))
(.setUseFragment history false)
(.setPathPrefix history "")
(.setEnabled history true)
(let [navigation (listen history EventType/NAVIGATE)]
(go
(while true
(let [token (.-token (<! navigation))]
(secretary/dispatch! token)))))
(events/listen js/document "click" (fn [e]
(let [path (.getPath (.parse Uri (.-href (.-target e))))
title (.-title (.-target e))
matches-path? (secretary/locate-route path)]
(when matches-path?
(. history (setToken path title))
(.preventDefault e)))))
@shiftb
Copy link
Author

shiftb commented Jul 10, 2014

secretary's API changed and now we use secretary/locate-route instead of secretary/any-matches?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment