Skip to content

Commit 6765b70

Browse files
committed
js: used native forEach()
1 parent 41b2911 commit 6765b70

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
@@ -55,7 +55,7 @@
5555
this.reposition();
5656
});
5757

58-
forEach(elem.querySelectorAll('.tracy-icons a'), link => {
58+
elem.querySelectorAll('.tracy-icons a').forEach(link => {
5959
link.addEventListener('click', e => {
6060
clearTimeout(elem.Tracy.displayTimeout);
6161
if (link.rel === 'close') {
@@ -252,7 +252,7 @@
252252

253253

254254
initTabs(elem) {
255-
forEach(elem.getElementsByTagName('a'), link => {
255+
elem.querySelectorAll('a').forEach(link => {
256256
link.addEventListener('click', e => {
257257
if (link.rel === 'close') {
258258
this.close();
@@ -307,7 +307,7 @@
307307

308308
autoHideLabels() {
309309
var width = getWindowSize().width;
310-
forEach(this.elem.children, function (ul) {
310+
Array.from(this.elem.children).forEach(ul => {
311311
var labels = ul.querySelectorAll('.tracy-label');
312312
for (var i = labels.length - 1; i >= 0 && ul.clientWidth >= width; i--) {
313313
labels.item(i).hidden = true;
@@ -368,7 +368,7 @@
368368
Debug.layer.style.display = 'block';
369369
Debug.bar.init();
370370

371-
forEach(document.querySelectorAll('.tracy-panel'), panel => {
371+
document.querySelectorAll('.tracy-panel').forEach(panel => {
372372
Debug.panels[panel.id] = new Panel(panel.id);
373373
Debug.panels[panel.id].dumps = dumps;
374374
Debug.panels[panel.id].restorePosition();
@@ -380,7 +380,7 @@
380380

381381

382382
static loadAjax(content, dumps) {
383-
forEach(Debug.layer.querySelectorAll('.tracy-panel.tracy-ajax'), panel => {
383+
Debug.layer.querySelectorAll('.tracy-panel.tracy-ajax').forEach(panel => {
384384
Debug.panels[panel.id].savePosition();
385385
delete Debug.panels[panel.id];
386386
panel.parentNode.removeChild(panel);
@@ -396,7 +396,7 @@
396396
ajaxBar = document.getElementById('tracy-ajax-bar');
397397
Debug.bar.elem.appendChild(ajaxBar);
398398

399-
forEach(document.querySelectorAll('.tracy-panel'), panel => {
399+
document.querySelectorAll('.tracy-panel').forEach(panel => {
400400
if (!Debug.panels[panel.id]) {
401401
Debug.panels[panel.id] = new Panel(panel.id);
402402
Debug.panels[panel.id].dumps = dumps;
@@ -491,7 +491,7 @@
491491

492492

493493
function evalScripts(elem) {
494-
forEach(elem.getElementsByTagName('script'), script => {
494+
elem.querySelectorAll('script').forEach(script => {
495495
if ((!script.hasAttribute('type') || script.type === 'text/javascript' || script.type === 'application/javascript') && !script.tracyEvaluated) {
496496
var dolly = script.ownerDocument.createElement('script');
497497
dolly.textContent = script.textContent;
@@ -579,7 +579,7 @@
579579
}
580580
};
581581

582-
forEach(options.handles, function (handle) {
582+
options.handles.forEach(handle => {
583583
handle.addEventListener('mousedown', onStart);
584584
handle.addEventListener('touchstart', onStart);
585585

@@ -638,11 +638,6 @@
638638
}
639639

640640

641-
function forEach(arr, cb) {
642-
Array.prototype.forEach.call(arr, cb);
643-
}
644-
645-
646641
if (document.currentScript) {
647642
var nonce = document.currentScript.getAttribute('nonce') || document.currentScript.nonce;
648643
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)