Add getTabs() and eachTab() methods to TabGroup

Closes #39
This commit is contained in:
Thomas Brouard 2017-09-14 17:23:49 +02:00
parent a2761ab147
commit b579379d88
2 changed files with 30 additions and 7 deletions

View file

@ -94,6 +94,20 @@ Retrieve an instance of `Tab` from its `id` (return `null` if not found).
Return the currently active tab (otherwise return `null`). Return the currently active tab (otherwise return `null`).
#### `tabGroup.getTabs()`
Return all registered tabs.
#### `tabGroup.eachTab(fn, thisArg)`
Loop through the list of tabs in `tabGroup` and execute the `fn` function for each tab. `fn` is called with the following parameters:
* `currentTab`: the current tab object.
* `index`: the index of the current tab being processed.
* `tabs`: the full array of tabs (similar to `tabGroup.getTabs()`).
`thisArg` (optional) is the value to use as `this` when executing `fn`.
### Tab ### Tab
Instances of `Tab` are returned by the `tabGroup.addTab()` method. Instances of `Tab` are returned by the `tabGroup.addTab()` method.

View file

@ -76,6 +76,15 @@ class TabGroup extends EventEmitter {
return null; return null;
} }
getTabs () {
return this.tabs;
}
eachTab (fn) {
this.tabs.forEach(fn);
return this;
}
getActiveTab () { getActiveTab () {
if (this.tabs.length === 0) return null; if (this.tabs.length === 0) return null;
return this.tabs[0]; return this.tabs[0];