Skip to content

Commit 0781fc5

Browse files
authored
Merge pull request #1476 from nextcloud-libraries/fix/register-batch
fix: allow to register multiple views at once
2 parents 3d0118e + a186d0e commit 0781fc5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/navigation/navigation.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,19 @@ export class Navigation extends TypedEventTarget<{ updateActive: UpdateActiveVie
5353
/**
5454
* Register a new view on the navigation
5555
*
56-
* @param view The view to register
56+
* @param views The views to register
5757
* @throws {Error} if a view with the same id is already registered
5858
* @throws {Error} if the registered view is invalid
5959
*/
60-
register(view: IView): void {
61-
if (this._views.find((search) => search.id === view.id)) {
62-
throw new Error(`IView id ${view.id} is already registered`)
60+
register(...views: IView[]): void {
61+
for (const view of views) {
62+
if (this._views.find((search) => search.id === view.id)) {
63+
throw new Error(`IView id ${view.id} is already registered`)
64+
}
65+
validateView(view)
6366
}
6467

65-
validateView(view)
66-
67-
this._views.push(view)
68+
this._views.push(...views)
6869
this.dispatchTypedEvent('update', new CustomEvent<never>('update') as UpdateViewsEvent)
6970
}
7071

0 commit comments

Comments
 (0)