diff options
| author | okayurisotto <okayurisotto@proton.me> | 2023-07-14 10:45:01 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-14 10:45:01 +0900 |
| commit | 2b6dbd4fcbec380d65b0c318932d9eeb3fcb3f7b (patch) | |
| tree | 125b6f724450c37bd1c025d5b3e09c50dc2b20c9 /packages/frontend/src | |
| parent | refactor: `substr` -> `substring` (#11273) (diff) | |
| download | sharkey-2b6dbd4fcbec380d65b0c318932d9eeb3fcb3f7b.tar.gz sharkey-2b6dbd4fcbec380d65b0c318932d9eeb3fcb3f7b.tar.bz2 sharkey-2b6dbd4fcbec380d65b0c318932d9eeb3fcb3f7b.zip | |
refactor: 可読性のため一部で`Array.prototype.at`を使うように (#11274)
* refactor: `Array.prototype.at`を使うように
* fixup! refactor: `Array.prototype.at`を使うように
Diffstat (limited to 'packages/frontend/src')
7 files changed, 18 insertions, 17 deletions
diff --git a/packages/frontend/src/components/MkDrive.vue b/packages/frontend/src/components/MkDrive.vue index 201a6ccdc8..aff227da40 100644 --- a/packages/frontend/src/components/MkDrive.vue +++ b/packages/frontend/src/components/MkDrive.vue @@ -568,7 +568,7 @@ function fetchMoreFolders() { os.api('drive/folders', { folderId: folder.value ? folder.value.id : null, type: props.type, - untilId: folders.value[folders.value.length - 1].id, + untilId: folders.value.at(-1)?.id, limit: max + 1, }).then(folders => { if (folders.length === max + 1) { @@ -591,7 +591,7 @@ function fetchMoreFiles() { os.api('drive/files', { folderId: folder.value ? folder.value.id : null, type: props.type, - untilId: files.value[files.value.length - 1].id, + untilId: files.value.at(-1)?.id, limit: max + 1, }).then(files => { if (files.length === max + 1) { diff --git a/packages/frontend/src/components/MkMiniChart.vue b/packages/frontend/src/components/MkMiniChart.vue index 89050e10f0..e884455709 100644 --- a/packages/frontend/src/components/MkMiniChart.vue +++ b/packages/frontend/src/components/MkMiniChart.vue @@ -59,8 +59,8 @@ function draw(): void { polygonPoints = `0,${ viewBoxY } ${ polylinePoints } ${ viewBoxX },${ viewBoxY }`; - headX = _polylinePoints[_polylinePoints.length - 1][0]; - headY = _polylinePoints[_polylinePoints.length - 1][1]; + headX = _polylinePoints.at(-1)![0]; + headY = _polylinePoints.at(-1)![1]; } watch(() => props.src, draw, { immediate: true }); diff --git a/packages/frontend/src/components/MkPageWindow.vue b/packages/frontend/src/components/MkPageWindow.vue index 6318a9fd70..6e35ad4241 100644 --- a/packages/frontend/src/components/MkPageWindow.vue +++ b/packages/frontend/src/components/MkPageWindow.vue @@ -120,7 +120,7 @@ const contextmenu = $computed(() => ([{ function back() { history.pop(); - router.replace(history[history.length - 1].path, history[history.length - 1].key); + router.replace(history.at(-1)!.path, history.at(-1)!.key); } function reload() { diff --git a/packages/frontend/src/components/MkPagination.vue b/packages/frontend/src/components/MkPagination.vue index 661b04c365..b9a75f6002 100644 --- a/packages/frontend/src/components/MkPagination.vue +++ b/packages/frontend/src/components/MkPagination.vue @@ -233,7 +233,7 @@ const fetchMore = async (): Promise<void> => { ...(props.pagination.offsetMode ? { offset: offset.value, } : { - untilId: Array.from(items.value.keys())[items.value.size - 1], + untilId: Array.from(items.value.keys()).at(-1), }), }).then(res => { for (let i = 0; i < res.length; i++) { @@ -297,7 +297,7 @@ const fetchMoreAhead = async (): Promise<void> => { ...(props.pagination.offsetMode ? { offset: offset.value, } : { - sinceId: Array.from(items.value.keys())[items.value.size - 1], + sinceId: Array.from(items.value.keys()).at(-1), }), }).then(res => { if (res.length === 0) { diff --git a/packages/frontend/src/scripts/array.ts b/packages/frontend/src/scripts/array.ts index 4620c8b735..c9a146e707 100644 --- a/packages/frontend/src/scripts/array.ts +++ b/packages/frontend/src/scripts/array.ts @@ -78,8 +78,9 @@ export function maximum(xs: number[]): number { export function groupBy<T>(f: EndoRelation<T>, xs: T[]): T[][] { const groups = [] as T[][]; for (const x of xs) { - if (groups.length !== 0 && f(groups[groups.length - 1][0], x)) { - groups[groups.length - 1].push(x); + const lastGroup = groups.at(-1); + if (lastGroup !== undefined && f(lastGroup[0], x)) { + lastGroup.push(x); } else { groups.push([x]); } diff --git a/packages/frontend/src/widgets/server-metric/cpu-mem.vue b/packages/frontend/src/widgets/server-metric/cpu-mem.vue index c178ba5171..b9ba400b4d 100644 --- a/packages/frontend/src/widgets/server-metric/cpu-mem.vue +++ b/packages/frontend/src/widgets/server-metric/cpu-mem.vue @@ -121,10 +121,10 @@ function onStats(connStats) { cpuPolygonPoints = `${viewBoxX - (stats.length - 1)},${viewBoxY} ${cpuPolylinePoints} ${viewBoxX},${viewBoxY}`; memPolygonPoints = `${viewBoxX - (stats.length - 1)},${viewBoxY} ${memPolylinePoints} ${viewBoxX},${viewBoxY}`; - cpuHeadX = cpuPolylinePointsStats[cpuPolylinePointsStats.length - 1][0]; - cpuHeadY = cpuPolylinePointsStats[cpuPolylinePointsStats.length - 1][1]; - memHeadX = memPolylinePointsStats[memPolylinePointsStats.length - 1][0]; - memHeadY = memPolylinePointsStats[memPolylinePointsStats.length - 1][1]; + cpuHeadX = cpuPolylinePointsStats.at(-1)![0]; + cpuHeadY = cpuPolylinePointsStats.at(-1)![1]; + memHeadX = memPolylinePointsStats.at(-1)![0]; + memHeadY = memPolylinePointsStats.at(-1)![1]; cpuP = (connStats.cpu * 100).toFixed(0); memP = (connStats.mem.active / props.meta.mem.total * 100).toFixed(0); diff --git a/packages/frontend/src/widgets/server-metric/net.vue b/packages/frontend/src/widgets/server-metric/net.vue index 5a9134078d..817a422e63 100644 --- a/packages/frontend/src/widgets/server-metric/net.vue +++ b/packages/frontend/src/widgets/server-metric/net.vue @@ -94,10 +94,10 @@ function onStats(connStats) { inPolygonPoints = `${viewBoxX - (stats.length - 1)},${viewBoxY} ${inPolylinePoints} ${viewBoxX},${viewBoxY}`; outPolygonPoints = `${viewBoxX - (stats.length - 1)},${viewBoxY} ${outPolylinePoints} ${viewBoxX},${viewBoxY}`; - inHeadX = inPolylinePointsStats[inPolylinePointsStats.length - 1][0]; - inHeadY = inPolylinePointsStats[inPolylinePointsStats.length - 1][1]; - outHeadX = outPolylinePointsStats[outPolylinePointsStats.length - 1][0]; - outHeadY = outPolylinePointsStats[outPolylinePointsStats.length - 1][1]; + inHeadX = inPolylinePointsStats.at(-1)![0]; + inHeadY = inPolylinePointsStats.at(-1)![1]; + outHeadX = outPolylinePointsStats.at(-1)![0]; + outHeadY = outPolylinePointsStats.at(-1)![1]; inRecent = connStats.net.rx; outRecent = connStats.net.tx; |