mirror of
https://github.com/metosin/reitit.git
synced 2026-01-28 17:00:34 +00:00
Fix reitit.frontend.easy not correctly removing old event listeners
In 0.5.0 rfe start! fn started using first on-navigate callback to get the reference to History instance, so that user on-navigate can use rfe functions that need this reference. History implementations called on-navigate with the instance without event listeners set, so when stop! was called listeners weren't removed.
This commit is contained in:
parent
390cdb1e4e
commit
5651b4648a
1 changed files with 12 additions and 8 deletions
|
|
@ -26,11 +26,14 @@
|
||||||
(let [path (-get-path this)]
|
(let [path (-get-path this)]
|
||||||
(when (or (= goog.events.EventType.POPSTATE (.-type e))
|
(when (or (= goog.events.EventType.POPSTATE (.-type e))
|
||||||
(not= @last-fragment path))
|
(not= @last-fragment path))
|
||||||
(-on-navigate this path))))]
|
(-on-navigate this path))))
|
||||||
|
;; rfe start! uses first on-navigate call to store the
|
||||||
|
;; instance so it has to see the instance with listeners.
|
||||||
|
this (assoc this
|
||||||
|
:popstate-listener (gevents/listen js/window goog.events.EventType.POPSTATE handler false)
|
||||||
|
:hashchange-listener (gevents/listen js/window goog.events.EventType.HASHCHANGE handler false))]
|
||||||
(-on-navigate this (-get-path this))
|
(-on-navigate this (-get-path this))
|
||||||
(assoc this
|
this))
|
||||||
: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]
|
(-stop [this]
|
||||||
(gevents/unlistenByKey popstate-listener)
|
(gevents/unlistenByKey popstate-listener)
|
||||||
(gevents/unlistenByKey hashchange-listener)
|
(gevents/unlistenByKey hashchange-listener)
|
||||||
|
|
@ -115,11 +118,12 @@
|
||||||
(when (.hasFragment uri)
|
(when (.hasFragment uri)
|
||||||
(str "#" (.getFragment uri))))]
|
(str "#" (.getFragment uri))))]
|
||||||
(.pushState js/window.history nil "" path)
|
(.pushState js/window.history nil "" path)
|
||||||
(-on-navigate this path))))))]
|
(-on-navigate this path))))))
|
||||||
|
this (assoc this
|
||||||
|
:listen-key (gevents/listen js/window goog.events.EventType.POPSTATE handler false)
|
||||||
|
:click-listen-key (gevents/listen js/document goog.events.EventType.CLICK ignore-anchor-click))]
|
||||||
(-on-navigate this (-get-path this))
|
(-on-navigate this (-get-path this))
|
||||||
(assoc this
|
this))
|
||||||
:listen-key (gevents/listen js/window goog.events.EventType.POPSTATE handler false)
|
|
||||||
:click-listen-key (gevents/listen js/document goog.events.EventType.CLICK ignore-anchor-click))))
|
|
||||||
(-on-navigate [this path]
|
(-on-navigate [this path]
|
||||||
(on-navigate (rf/match-by-path router path) this))
|
(on-navigate (rf/match-by-path router path) this))
|
||||||
(-stop [this]
|
(-stop [this]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue