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 f9cbf10
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/pushy/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,28 @@
"Takes in three functions:
* dispatch-fn: the function that dispatches when a match is found
* match-fn: the function used to check if a particular route exists
* identity-fn: (optional) extract the route from value returned by match-fn"
* identity-fn: (optional) extract the route from value returned by match-fn
Options:
* prevent-default-when-no-match? Continue to prevent default events even if no routes match (default false)
* dispatch-on-match? Allow for a dispatch event over the same route. (default false)"
[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? false}}]

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

(replace-token! [_ token]
Expand Down

0 comments on commit f9cbf10

Please sign in to comment.