Skip to content

Commit

Permalink
Optimize events on handler
Browse files Browse the repository at this point in the history
By storing the targets only once per base node we spare some
unneccessary dom queries.
  • Loading branch information
tvdeyen committed Nov 30, 2023
1 parent 92c94ed commit 006454a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/javascript/alchemy_admin/utils/events.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export function on(eventName, baseSelector, targetSelector, callback) {
document.querySelectorAll(baseSelector).forEach((baseNode) => {
const targets = Array.from(baseNode.querySelectorAll(targetSelector))

baseNode.addEventListener(eventName, (evt) => {
const targets = Array.from(baseNode.querySelectorAll(targetSelector))
let currentNode = evt.target

while (currentNode !== baseNode) {
Expand Down

0 comments on commit 006454a

Please sign in to comment.