Skip to content

Commit c8cc8db

Browse files
committed
js: used native forEach()
1 parent 1a7ec6d commit c8cc8db

3 files changed

Lines changed: 11 additions & 16 deletions

File tree

src/Tracy/assets/Bar/bar.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
this.reposition();
5757
});
5858

59-
forEach(elem.querySelectorAll('.tracy-icons a'), link => {
59+
elem.querySelectorAll('.tracy-icons a').forEach(link => {
6060
link.addEventListener('click', e => {
6161
clearTimeout(elem.Tracy.displayTimeout);
6262
if (link.rel === 'close') {
@@ -257,7 +257,7 @@
257257

258258

259259
initTabs(elem) {
260-
forEach(elem.getElementsByTagName('a'), link => {
260+
elem.querySelectorAll('a').forEach(link => {
261261
link.addEventListener('click', e => {
262262
if (link.rel === 'close') {
263263
this.close();
@@ -316,7 +316,7 @@
316316

317317
autoHideLabels() {
318318
var width = getWindowSize().width;
319-
forEach(this.elem.children, function (ul) {
319+
Array.from(this.elem.children).forEach(ul => {
320320
var labels = ul.querySelectorAll('.tracy-label');
321321
for (var i = labels.length - 1; i >= 0 && ul.clientWidth >= width; i--) {
322322
labels.item(i).hidden = true;
@@ -377,7 +377,7 @@
377377
Debug.layer.style.display = 'block';
378378
Debug.bar.init();
379379

380-
forEach(document.querySelectorAll('.tracy-panel'), panel => {
380+
document.querySelectorAll('.tracy-panel').forEach(panel => {
381381
Debug.panels[panel.id] = new Panel(panel.id);
382382
Debug.panels[panel.id].dumps = dumps;
383383
Debug.panels[panel.id].restorePosition();
@@ -389,7 +389,7 @@
389389

390390

391391
static loadAjax(content, dumps) {
392-
forEach(Debug.layer.querySelectorAll('.tracy-panel.tracy-ajax'), panel => {
392+
Debug.layer.querySelectorAll('.tracy-panel.tracy-ajax').forEach(panel => {
393393
Debug.panels[panel.id].savePosition();
394394
delete Debug.panels[panel.id];
395395
panel.parentNode.removeChild(panel);
@@ -405,7 +405,7 @@
405405
ajaxBar = document.getElementById('tracy-ajax-bar');
406406
Debug.bar.elem.appendChild(ajaxBar);
407407

408-
forEach(document.querySelectorAll('.tracy-panel'), panel => {
408+
document.querySelectorAll('.tracy-panel').forEach(panel => {
409409
if (!Debug.panels[panel.id]) {
410410
Debug.panels[panel.id] = new Panel(panel.id);
411411
Debug.panels[panel.id].dumps = dumps;
@@ -500,7 +500,7 @@
500500

501501

502502
function evalScripts(elem) {
503-
forEach(elem.getElementsByTagName('script'), script => {
503+
elem.querySelectorAll('script').forEach(script => {
504504
if ((!script.hasAttribute('type') || script.type === 'text/javascript' || script.type === 'application/javascript') && !script.tracyEvaluated) {
505505
var dolly = script.ownerDocument.createElement('script');
506506
dolly.textContent = script.textContent;
@@ -588,7 +588,7 @@
588588
}
589589
};
590590

591-
forEach(options.handles, function (handle) {
591+
options.handles.forEach(handle => {
592592
handle.addEventListener('mousedown', onStart);
593593
handle.addEventListener('touchstart', onStart);
594594

@@ -647,11 +647,6 @@
647647
}
648648

649649

650-
function forEach(arr, cb) {
651-
Array.prototype.forEach.call(arr, cb);
652-
}
653-
654-
655650
if (document.currentScript) {
656651
var nonce = document.currentScript.getAttribute('nonce') || document.currentScript.nonce;
657652
var contentId = document.currentScript.dataset.id;

src/Tracy/assets/Dumper/dumper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{
1212
static init(repository, context) {
1313
if (repository) {
14-
[].forEach.call((context || document).querySelectorAll('.tracy-dump[data-tracy-dump]'), function(el) {
14+
(context || document).querySelectorAll('.tracy-dump[data-tracy-dump]').forEach(el => {
1515
try {
1616
el.appendChild(build(JSON.parse(el.getAttribute('data-tracy-dump')), repository, el.classList.contains('tracy-collapsed')));
1717
el.classList.remove('tracy-collapsed');

src/Tracy/assets/Toggle/toggle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@
7979
}
8080

8181
window.addEventListener('unload', function() {
82-
toggles = [].map.call(saved, function(el) {
82+
toggles = saved.map(function(el) {
8383
var item = {path: [], text: el.textContent, show: !el.classList.contains('tracy-collapsed')};
8484
do {
85-
item.path.unshift([].indexOf.call(el.parentNode.children, el));
85+
item.path.unshift(Array.from(el.parentNode.children).indexOf(el));
8686
el = el.parentNode;
8787
} while (el && el !== baseEl);
8888
return item;

0 commit comments

Comments
 (0)