Skip to content

Commit

Permalink
feat: introduce buildOnce method for navigation manager
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Oct 17, 2024
1 parent 125b9e7 commit b3e195b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/nuxt/middleware/layout.global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import { injectNavigationManager } from '@vuecs/navigation';

export default defineNuxtRouteMiddleware(async (route) => {
const manager = injectNavigationManager();
await manager.build({ path: route.fullPath });
await manager.buildOnce({ path: route.fullPath });
});
8 changes: 6 additions & 2 deletions packages/navigation/src/manager/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ export class NavigationManager extends EventEmitter<{
return this.items.filter((item) => item.level === tier);
}

async build(options: NavigationManagerBuildOptions) : Promise<NavigationItemNormalized[]> {
if (this.built) {
async buildOnce(options: NavigationManagerBuildOptions) : Promise<NavigationItemNormalized[]> {
if (this.built && !options.reset) {
return this.items;
}

return this.build(options);
}

async build(options: NavigationManagerBuildOptions) : Promise<NavigationItemNormalized[]> {
this.built = true;

this.items = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/navigation/src/manager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import type { NavigationItem, NavigationItemsFn } from '../types';

export type NavigationManagerBuildOptions = {
path: string
path: string,
reset?: boolean
};

export type NavigationManagerOptions = {
Expand Down

0 comments on commit b3e195b

Please sign in to comment.