From 3fd2972b7ccbb8cfa81d829b61c3dffae15250cb Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 4 Mar 2021 14:04:47 +0800 Subject: [PATCH] chore: array fill (#8263) --- src/calendar/components/Month.tsx | 8 ++------ src/index-bar/index.tsx | 8 +++----- src/loading/index.tsx | 5 +---- src/number-keyboard/index.tsx | 7 +++---- src/rate/index.tsx | 12 +++++------- src/skeleton/index.tsx | 15 +++++---------- 6 files changed, 19 insertions(+), 36 deletions(-) diff --git a/src/calendar/components/Month.tsx b/src/calendar/components/Month.tsx index 7e2601722..0eeabbb9b 100644 --- a/src/calendar/components/Month.tsx +++ b/src/calendar/components/Month.tsx @@ -195,13 +195,9 @@ export default createComponent({ } }; - const placeholders = computed(() => { - const rows: DayItem[] = []; + const placeholders = computed(() => { const count = Math.ceil((totalDay.value + offset.value) / 7); - for (let day = 1; day <= count; day++) { - rows.push({ type: 'placeholder' }); - } - return rows; + return Array(count).fill({ type: 'placeholder' }); }); const days = computed(() => { diff --git a/src/index-bar/index.tsx b/src/index-bar/index.tsx index 143946290..bb46d2bc7 100644 --- a/src/index-bar/index.tsx +++ b/src/index-bar/index.tsx @@ -41,12 +41,10 @@ export type IndexBarProvide = { }; function genAlphabet() { - const indexList = []; const charCodeOfA = 'A'.charCodeAt(0); - - for (let i = 0; i < 26; i++) { - indexList.push(String.fromCharCode(charCodeOfA + i)); - } + const indexList = Array(26) + .fill('') + .map((_, i) => String.fromCharCode(charCodeOfA + i)); return indexList; } diff --git a/src/loading/index.tsx b/src/loading/index.tsx index fd04b204e..2dfe9a5f1 100644 --- a/src/loading/index.tsx +++ b/src/loading/index.tsx @@ -3,10 +3,7 @@ import { createNamespace, addUnit, getSizeStyle } from '../utils'; const [createComponent, bem] = createNamespace('loading'); -const SpinIcon: JSX.Element[] = []; -for (let i = 0; i < 12; i++) { - SpinIcon.push(); -} +const SpinIcon: JSX.Element[] = Array(12).fill(); const CircularIcon = ( diff --git a/src/number-keyboard/index.tsx b/src/number-keyboard/index.tsx index dce0ad21d..6d4da08bd 100644 --- a/src/number-keyboard/index.tsx +++ b/src/number-keyboard/index.tsx @@ -85,10 +85,9 @@ export default createComponent({ const root = ref(); const genBasicKeys = () => { - const keys: KeyConfig[] = []; - for (let i = 1; i <= 9; i++) { - keys.push({ text: i }); - } + const keys: KeyConfig[] = Array(9) + .fill('') + .map((_, i) => ({ text: i + 1 })); if (props.randomKeyOrder) { keys.sort(() => (Math.random() > 0.5 ? 1 : -1)); diff --git a/src/rate/index.tsx b/src/rate/index.tsx index 90eea1100..9fa524f1a 100644 --- a/src/rate/index.tsx +++ b/src/rate/index.tsx @@ -73,13 +73,11 @@ export default createComponent({ const untouchable = () => props.readonly || props.disabled || !props.touchable; - const list = computed(() => { - const list: RateStatus[] = []; - for (let i = 1; i <= props.count; i++) { - list.push(getRateStatus(props.modelValue, i, props.allowHalf)); - } - return list; - }); + const list = computed(() => + Array(props.count) + .fill('') + .map((_, i) => getRateStatus(props.modelValue, i + 1, props.allowHalf)) + ); const select = (index: number) => { if (!props.disabled && !props.readonly && index !== props.modelValue) { diff --git a/src/skeleton/index.tsx b/src/skeleton/index.tsx index 3b003445d..7eac6bd8b 100644 --- a/src/skeleton/index.tsx +++ b/src/skeleton/index.tsx @@ -73,17 +73,12 @@ export default createComponent({ return rowWidth; }; - const renderRows = () => { - const Rows: JSX.Element[] = []; - - for (let i = 0; i < props.row; i++) { - Rows.push( + const renderRows = () => + Array(props.row) + .fill('') + .map((_, i) => (
- ); - } - - return Rows; - }; + )); return () => { if (!props.loading) {