-
-
Save nakkaya/fb5acbebf8ff7a4f468fa92b6a0b7342 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(e/def !history (e/client (history/new-goog-history))) | |
(e/def path (e/client (new (m/relieve {} (history/path> !history))))) | |
#?(:cljs | |
(defn navigate! [^js !history href] (.setToken !history href))) | |
;; then to navigate | |
(navigate! !history "/some-page") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app.history | |
#?(:cljs | |
(:import [goog.history Html5History EventType])) | |
(:require | |
#?(:cljs goog.events) | |
[hyperfiddle.electric :as e] | |
[hyperfiddle.electric-dom2 :as dom] | |
[missionary.core :as m])) | |
#?(:cljs | |
(defn new-goog-history [] | |
(doto (Html5History. js/window) | |
(.setUseFragment true) | |
(.setPathPrefix (str js/window.location.protocol | |
"//" | |
js/window.location.host | |
"/app/")) | |
(.setEnabled true)))) | |
#?(:cljs | |
(defn path> [^js h] | |
(m/observe (fn mount [!] | |
(let [k (goog.events/listen h EventType.NAVIGATE (fn [^js e] (! (.-token e))))] | |
(! (.getToken h)) | |
(fn unmount [] | |
(goog.events/unlistenByKey k))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment