chore: array fill (#8263)

This commit is contained in:
neverland 2021-03-04 14:04:47 +08:00 committed by GitHub
parent 12be46fad8
commit 3fd2972b7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 36 deletions

View File

@ -195,13 +195,9 @@ export default createComponent({
} }
}; };
const placeholders = computed(() => { const placeholders = computed<DayItem[]>(() => {
const rows: DayItem[] = [];
const count = Math.ceil((totalDay.value + offset.value) / 7); const count = Math.ceil((totalDay.value + offset.value) / 7);
for (let day = 1; day <= count; day++) { return Array(count).fill({ type: 'placeholder' });
rows.push({ type: 'placeholder' });
}
return rows;
}); });
const days = computed(() => { const days = computed(() => {

View File

@ -41,12 +41,10 @@ export type IndexBarProvide = {
}; };
function genAlphabet() { function genAlphabet() {
const indexList = [];
const charCodeOfA = 'A'.charCodeAt(0); const charCodeOfA = 'A'.charCodeAt(0);
const indexList = Array(26)
for (let i = 0; i < 26; i++) { .fill('')
indexList.push(String.fromCharCode(charCodeOfA + i)); .map((_, i) => String.fromCharCode(charCodeOfA + i));
}
return indexList; return indexList;
} }

View File

@ -3,10 +3,7 @@ import { createNamespace, addUnit, getSizeStyle } from '../utils';
const [createComponent, bem] = createNamespace('loading'); const [createComponent, bem] = createNamespace('loading');
const SpinIcon: JSX.Element[] = []; const SpinIcon: JSX.Element[] = Array(12).fill(<i />);
for (let i = 0; i < 12; i++) {
SpinIcon.push(<i />);
}
const CircularIcon = ( const CircularIcon = (
<svg class={bem('circular')} viewBox="25 25 50 50"> <svg class={bem('circular')} viewBox="25 25 50 50">

View File

@ -85,10 +85,9 @@ export default createComponent({
const root = ref<HTMLElement>(); const root = ref<HTMLElement>();
const genBasicKeys = () => { const genBasicKeys = () => {
const keys: KeyConfig[] = []; const keys: KeyConfig[] = Array(9)
for (let i = 1; i <= 9; i++) { .fill('')
keys.push({ text: i }); .map((_, i) => ({ text: i + 1 }));
}
if (props.randomKeyOrder) { if (props.randomKeyOrder) {
keys.sort(() => (Math.random() > 0.5 ? 1 : -1)); keys.sort(() => (Math.random() > 0.5 ? 1 : -1));

View File

@ -73,13 +73,11 @@ export default createComponent({
const untouchable = () => const untouchable = () =>
props.readonly || props.disabled || !props.touchable; props.readonly || props.disabled || !props.touchable;
const list = computed(() => { const list = computed<RateStatus[]>(() =>
const list: RateStatus[] = []; Array(props.count)
for (let i = 1; i <= props.count; i++) { .fill('')
list.push(getRateStatus(props.modelValue, i, props.allowHalf)); .map((_, i) => getRateStatus(props.modelValue, i + 1, props.allowHalf))
} );
return list;
});
const select = (index: number) => { const select = (index: number) => {
if (!props.disabled && !props.readonly && index !== props.modelValue) { if (!props.disabled && !props.readonly && index !== props.modelValue) {

View File

@ -73,17 +73,12 @@ export default createComponent({
return rowWidth; return rowWidth;
}; };
const renderRows = () => { const renderRows = () =>
const Rows: JSX.Element[] = []; Array(props.row)
.fill('')
for (let i = 0; i < props.row; i++) { .map((_, i) => (
Rows.push(
<div class={bem('row')} style={{ width: addUnit(getRowWidth(i)) }} /> <div class={bem('row')} style={{ width: addUnit(getRowWidth(i)) }} />
); ));
}
return Rows;
};
return () => { return () => {
if (!props.loading) { if (!props.loading) {