Problem/Motivation

A querySelectorAll() method returns NodeList value and which has forEach() method. A forEach() method calls each element in NodeList so no need to count NodeList item and iterate in a for loop.

For example, active-link.js.

Proposed resolution

Use NodeList.forEach() and remove item counting and a for loop.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3531994

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tom konda created an issue. See original summary.

tom konda’s picture

Status: Active » Needs work

tom konda’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

With my javascript eyes on this seems like a good conversion, leaning on tests that active-link.js breakage would show.

oily’s picture

Are there not other places where this fix can be applied?

oily’s picture

There appear to be several instances in those files where the same sub-optimal syntax is used. Should they be included in this issue or in a follow-up?

  • nod_ committed 93279d3c on 11.x
    Issue #3531994 by tom konda: Replace for loop with forEach in active-...
nod_’s picture

Title: Remove no needed NodeList item counting and for loop after querySelectorAll() » Replace for loop with forEach in active-links.js and displace.js
Status: Reviewed & tested by the community » Fixed

Let's do follow-ups, I'd rather get that in regularly than wait 6 months for a big MR.

Committed 93279d3 and pushed to 11.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.