Skip to content

Commit

Permalink
add dispatch-on-match? option.
Browse files Browse the repository at this point in the history
Adds an option to allow for a dispatch on an already-matched route.
  • Loading branch information
featheredtoast committed Dec 7, 2017
1 parent ce02504 commit e1f59a7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/pushy/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,23 @@
* match-fn: the function used to check if a particular route exists
* identity-fn: (optional) extract the route from value returned by match-fn"
[dispatch-fn match-fn &
{:keys [processable-url? identity-fn prevent-default-when-no-match?]
{:keys [processable-url? identity-fn prevent-default-when-no-match? dispatch-on-match?]
:or {processable-url? processable-url?
identity-fn identity
prevent-default-when-no-match? (constantly false)}}]
prevent-default-when-no-match? (constantly false)
dispatch-on-match? (constantly false)}}]

(let [history (new-history)
event-keys (atom nil)]
(reify
IHistory
(set-token! [_ token]
(when (and (dispatch-on-match? token) (= token (.getToken history)))
(. history (replaceToken token)))
(. history (setToken token)))
(set-token! [_ token title]
(when (and (dispatch-on-match? token) (= token (.getToken history)))
(. history (replaceToken token title)))
(. history (setToken token title)))

(replace-token! [_ token]
Expand Down

0 comments on commit e1f59a7

Please sign in to comment.