day8 / re-com

A ClojureScript library of reusable components for Reagent
https://re-com.day8.com.au
MIT License
796 stars 147 forks source link

horizontal-bar-tabs: Suppress redundant on-click handler calls #333

Closed hipitihop closed 5 months ago

hipitihop commented 9 months ago

Current behavior horizontal-bar-tabs and variants call the on-click handler even there is no change to the currently selected button/tab. In turn, this places the onus on the handler fn or if dispatching a re-frame event, the re-frame handler, to make an additional check for the redundancy instead of the simpler handler as follows:

[rc/horizontal-bar-tabs
   :tabs      @(subscribe [::choices])
   :model     @(subscribe [::current-choice])
   :on-change #(dispatch [::choice-changed {:id %}])

Expected behavior If the user clicks on the same button as currently selected, don't call the on-click handler fn.

Effects

hipitihop commented 6 months ago

Reopening as I don't see re-com release, and existing code is defensive. This probably needs to be reproduced, then update to new re-com, then remove defensive code and retest:

kimo-k commented 6 months ago

Hey @hipitihop, I just cut a release. Here's a branch you can use to test it out: https://github.com/day8/rf8.day8.com.au/pull/72

hipitihop commented 5 months ago

Merged and confirmed. closing. Thanks @kimo-k