Skip to content

Commit cc0ffe6

Browse files
committed
perf: remove TabBarItem index key
1 parent 251a01a commit cc0ffe6

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/core/src/context.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { OUTPUT_NAME } from './constant'
1818
import { writeDeclaration } from './declaration'
1919
import { checkPagesJsonFileSync, getPathSets, writeFileWithLock } from './files'
2020
import { resolveOptions } from './options'
21-
import { PAGE_TYPE_KEY, PageFile } from './pageFile'
21+
import { PAGE_TYPE_KEY, PageFile, TABBAR_INDEX_KEY } from './pageFile'
2222
import {
2323
debug,
2424
invalidatePagesModule,
@@ -278,7 +278,7 @@ export class Context {
278278
}
279279

280280
private async getTabBarMerged(): Promise<TabBar | undefined> {
281-
const tabBarItems: (TabBarItem & { index: number })[] = []
281+
const tabBarItems: (TabBarItem)[] = []
282282
for (const [_, pf] of this.pageFiles) {
283283
const tabbar = await pf.getTabBar()
284284
if (tabbar) {
@@ -300,12 +300,15 @@ export class Context {
300300
pagePaths.set(item.pagePath, true)
301301
}
302302

303-
tabBarItems.sort((a, b) => a.index - b.index)
303+
tabBarItems.sort((a, b) => {
304+
const aIdx = (a as any)[TABBAR_INDEX_KEY] || 0
305+
const bIdx = (b as any)[TABBAR_INDEX_KEY] || 0
306+
return aIdx - bIdx
307+
})
304308

305309
for (const item of tabBarItems) {
306310
if (!pagePaths.has(item.pagePath)) {
307-
const { index: _, ...tabbar } = item
308-
tabBar.list.push(tabbar)
311+
tabBar.list.push(item)
309312
}
310313
}
311314

packages/core/src/pageFile.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { getRouteBlock, getRouteSfcBlock } from './customBlock'
1212
import { babelGenerate, debug, parseCode } from './utils'
1313

1414
export const PAGE_TYPE_KEY = Symbol.for('type')
15+
export const TABBAR_INDEX_KEY = Symbol.for('index')
1516

1617
export class PageFile {
1718
ctx: Context
@@ -44,7 +45,7 @@ export class PageFile {
4445
}
4546
}
4647

47-
public async getTabBar(forceUpdate = false): Promise<TabBarItem & { index: number } | undefined> {
48+
public async getTabBar(forceUpdate = false): Promise<TabBarItem | undefined> {
4849
if (forceUpdate || !this.meta) {
4950
await this.read()
5051
}
@@ -58,7 +59,7 @@ export class PageFile {
5859
return {
5960
...tabBar,
6061
pagePath: tabBar.pagePath || this.uri,
61-
index: tabBar.index || 0,
62+
[TABBAR_INDEX_KEY]: tabBar.index || 0,
6263
}
6364
}
6465

0 commit comments

Comments
 (0)