htmx icon indicating copy to clipboard operation
htmx copied to clipboard

class-tools extension will only handle the last operation defined in `classes`

Open twidi opened this issue 3 years ago • 1 comments

Due to how closures work, when the function defined in setTimeout is called, the classOperation will be the last one in the for loop.

https://github.com/bigskysoftware/htmx/blob/v1.7.0/src/ext/class-tools.js#L52

So having foo add:1, bar remove:2 => foo will never be added.

The solution is to move the calls to setTimeout in a function that will take classOperation as an argument.

cf https://medium.com/@axionoso/watch-out-when-using-settimeout-in-for-loop-js-75a047e27a5f

twidi avatar May 19 '22 21:05 twidi

great catch!

would you mind putting together a pull request for this?

1cg avatar May 26 '22 23:05 1cg