short circuit DOM node looping when handling events for '*' (all) query selector #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a very small change that may have a very large impact on performance for handling events in low-powered devices and unusually large DOM structures.
The current version of the code, in
utils/listener.js
file at thematches
function, performs aquerySelectorAll
on the parent node of the node where the event occurred. The list of nodes are then compared against the node on which the event occurred in order to verify that the clicked node should have its events tracked.this works very well and in general is optimized code.
However, ProdPerfect's auto tracking script uses a
*
query selector to state, for example, that all clicks on any DOM element should be recorded. In this case, the use of the query selector and loop are not needed. The node was clicked and since all clicked are being recorded, no check is necessary to see if this node should have events recorded.This pull requests adds a single line of code to the first line of the
matches
function which will check for the*
query selector and immediatelyreturn true
if it's found.The net result of this is the elimination of unnecessary DOM traversal, which can have a significant impact on low-power devices and unusually large DOM structures.