From b99e25ef4fdf30c8ccae0c652b1da6a994f5a098 Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Mon, 27 Aug 2018 14:22:21 +0300 Subject: [PATCH 1/2] Clean frontend routing docstrings --- modules/reitit-frontend/src/reitit/frontend/easy.cljs | 8 ++++---- modules/reitit-frontend/src/reitit/frontend/history.cljs | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/reitit-frontend/src/reitit/frontend/easy.cljs b/modules/reitit-frontend/src/reitit/frontend/easy.cljs index 6f812293..59313567 100644 --- a/modules/reitit-frontend/src/reitit/frontend/easy.cljs +++ b/modules/reitit-frontend/src/reitit/frontend/easy.cljs @@ -15,15 +15,15 @@ remove listeners using stop! call before calling start! again. Parameters: - - router The Reitit routing tree. - - on-navigate Function to be called when route changes. Takes two parameters, ´token´ and ´history´ object. + - router The Reitit router. + - on-navigate Function to be called when route changes. Takes two parameters, ´match´ and ´history´ object. Options: - :use-fragment (default true) If true, onhashchange and location hash are used to store the token." - [routes on-navigate opts] + [router on-navigate opts] (swap! history (fn [old-history] (rfh/stop! old-history) - (rfh/start! routes on-navigate opts)))) + (rfh/start! router on-navigate opts)))) (defn href ([k] diff --git a/modules/reitit-frontend/src/reitit/frontend/history.cljs b/modules/reitit-frontend/src/reitit/frontend/history.cljs index 9b59fe0e..03583cbe 100644 --- a/modules/reitit-frontend/src/reitit/frontend/history.cljs +++ b/modules/reitit-frontend/src/reitit/frontend/history.cljs @@ -102,11 +102,14 @@ (defn start! "This registers event listeners on HTML5 history and hashchange events. + + Returns History object. + When using with development workflow like Figwheel, rememeber to remove listeners using stop! call before calling start! again. Parameters: - - router The Reitit routing tree. + - router The Reitit router. - on-navigate Function to be called when route changes. Takes two parameters, ´match´ and ´history´ object. Options: From d7c025d9126dd5ec0f85585515ab35f3c09fe1d3 Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Mon, 27 Aug 2018 14:22:38 +0300 Subject: [PATCH 2/2] Fix FragmentHistory -stop method --- .../reitit-frontend/src/reitit/frontend/history.cljs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/reitit-frontend/src/reitit/frontend/history.cljs b/modules/reitit-frontend/src/reitit/frontend/history.cljs index 03583cbe..2bad0bce 100644 --- a/modules/reitit-frontend/src/reitit/frontend/history.cljs +++ b/modules/reitit-frontend/src/reitit/frontend/history.cljs @@ -16,7 +16,7 @@ ;; This version listens for both pop-state and hash-change for ;; compatibility for old browsers not supporting History API. -(defrecord FragmentHistory [on-navigate router listen-key last-fragment] +(defrecord FragmentHistory [on-navigate router popstate-listener hashchange-listener last-fragment] History (-init [this] ;; Link clicks and e.g. back button trigger both events, if fragment is same as previous ignore second event. @@ -30,12 +30,11 @@ (-on-navigate this path))))] (-on-navigate this (-get-path this)) (assoc this - :listen-key (gevents/listen js/window - #js [goog.events.EventType.POPSTATE goog.events.EventType.HASHCHANGE] - handler - false)))) + :popstate-listener (gevents/listen js/window goog.events.EventType.POPSTATE handler false) + :hashchange-listener (gevents/listen js/window goog.events.EventType.HASHCHANGE handler false)))) (-stop [this] - (gevents/unlistenByKey listen-key)) + (gevents/unlistenByKey popstate-listener) + (gevents/unlistenByKey hashchange-listener)) (-on-navigate [this path] (reset! last-fragment path) (on-navigate (rf/match-by-path router path) this))