kibu-australia / pushy

Clojurescript library for quick and easy HTML5 pushState
Eclipse Public License 1.0
223 stars 28 forks source link

Add ability to instruct pushy to ignore certain elements #18

Closed tomconnors closed 7 years ago

tomconnors commented 8 years ago

In a Reagent project, I need to be able to handle clicks on an anchor differently depending upon whether the resource at the anchor's href is "locked". This change would allow me to change some code that looks like this:

[:a {:href "#"
     :on-click (fn [e]
                 (if lock
                   (do
                     (.preventDefault e)
                     (dispatch
                      [:lock/show-remittance-dialog (:entity lock)]))
                   (history/go!
                    (routes/url-for :resource entity))))}
 "Edit"]

into code that looks like this:

[:a {:href (routes/url-for :resource entity)
     :data-pushy-ignore (boolean lock)
     :on-click (fn [e]
                 (when lock
                   (.preventDefault e)
                   (dispatch
                    [:lock/show-remittance-dialog (:entity lock)])))}
 "Edit"]

I think the latter is superior because users can right click + open in new tab. I also think it reads a bit better.