Closed Bug 553539 Opened 14 years ago Closed 14 years ago

Provide a helper function for common toolbar iteration pattern

Categories

(Toolkit :: Toolbars and Toolbar Customization, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9.3a4

People

(Reporter: dao, Assigned: dao)

Details

Attachments

(1 file, 1 obsolete file)

Attached patch patch (obsolete) — Splinter Review
Note that I'm using Array.slice(...).forEach( instead of Array.forEach(... so that toolbars can be removed in the callback.
Attachment #433526 - Flags: review?(neil)
+    for (let i = 0; i < toolbar.childNodes.length; ++i) {
can we use childElementCount here?

+      let item = toolbar.childNodes[i];
will this work? toolbar.children[i]

+      if (item.firstChild && item.firstChild.localName == "menubar")
firstElementChild?

+function forEachToolbar(cb) {
+  Array.slice(gToolbox.childNodes).forEach(function (toolbar) {
+    if (isCustomizableToolbar(toolbar))
+      cb(toolbar);
+  });
+}

How about?
Array.slice(gToolbox.childNodes).filter(isCustomizableToolbar).forEach(cb);
+function forEachToolbar(cb) {
s/cb/callback/g ?
Why would toolbar.children be better than toolbar.childNodes and firstElementChild better than firstChild? This isn't HTML.
(In reply to comment #1)
> How about?
> Array.slice(gToolbox.childNodes).filter(isCustomizableToolbar).forEach(cb);
Surely if you filter them you don't need to slice first.
Attached patch patch v2Splinter Review
using filter
Attachment #433526 - Attachment is obsolete: true
Attachment #433543 - Flags: review?(neil)
Attachment #433526 - Flags: review?(neil)
Comment on attachment 433543 [details] [diff] [review]
patch v2

>+function forEachToolbar(callback) {
[Is it too obvious to call this forEachCustomizableToolbar?]
Attachment #433543 - Flags: review?(neil) → review+
I mused about this as well. It's a bit long, but I guess it's still the better name.
http://hg.mozilla.org/mozilla-central/rev/15e4e239321a
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3a4
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: