Skip to content

Commit 500b66f

Browse files
committed
[accountant] internal refactoring
Refactoring `find-href` to not use an anonymous function. Also, cleans up meta-key, alt-key, etc to be called properly at attributes, not functions.
1 parent 1eee43d commit 500b66f

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.1.5
2+
* Internal refactoring
3+
* Extended browser event gating for meta key, alt key, ctrl key, shift key, etc.
4+
15
0.1.4
26
* Modify `navigate!` to not suppress browser events when the user tries to open a new tab
37

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ browsers will be left behind.
2222
Just add the following to your `project.clj`:
2323

2424
```clojure
25-
:dependencies [venantius/accountant "0.1.4"]
25+
:dependencies [venantius/accountant "0.1.5"]
2626
```
2727

2828
## Usage

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject venantius/accountant "0.1.4"
1+
(defproject venantius/accountant "0.1.5"
22
:description "Navigation for Single-Page Applications Made Easy."
33
:url "http://github.com/venantius/accountant"
44
:license {:name "Eclipse Public License"

src/accountant/core.cljs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@
2929
"Given a DOM element that may or may not be a link, traverse up the DOM tree
3030
to see if any of its parents are links. If so, return the href content."
3131
[e]
32-
((fn [e]
33-
(if-let [href (.-href e)]
34-
href
35-
(when-let [parent (.-parentNode e)]
36-
(recur parent)))) (.-target e)))
32+
(if-let [href (.-href e)]
33+
href
34+
(when-let [parent (.-parentNode e)]
35+
(recur parent))))
3736

3837
(defn- prevent-reload-on-known-path
3938
"Create a click handler that blocks page reloads for known routes in
@@ -43,15 +42,16 @@
4342
js/document
4443
"click"
4544
(fn [e]
46-
(let [button (.-button e)
47-
meta-key (.metaKey e)
48-
alt-key (.altKey e)
49-
ctrl-key (.ctrlKey e)
50-
shift-key (.shiftKey e)
45+
(let [target (.-target e)
46+
button (.-button e)
47+
meta-key (.-metaKey e)
48+
alt-key (.-altKey e)
49+
ctrl-key (.-ctrlKey e)
50+
shift-key (.-shiftKey e)
5151
any-key (or meta-key alt-key ctrl-key shift-key)
52-
href (find-href e)
52+
href (find-href target)
5353
path (.getPath (.parse Uri href))
54-
title (.-title (.-target e))]
54+
title (.-title target)]
5555
(when (and (not any-key) (= button 0) (secretary/locate-route path))
5656
(. history (setToken path title))
5757
(.preventDefault e))))))

0 commit comments

Comments
 (0)