chore: prefer arrow function shorthand

This commit is contained in:
chenjiahan 2021-03-02 17:45:12 +08:00
parent 2fd0d54da1
commit a0addef294
42 changed files with 98 additions and 249 deletions

View File

@ -51,9 +51,7 @@ export default createComponent({
emits: ['select', 'cancel', 'update:show'],
setup(props, { slots, emit }) {
const onUpdateShow = (show: boolean) => {
emit('update:show', show);
};
const onUpdateShow = (show: boolean) => emit('update:show', show);
const onCancel = () => {
onUpdateShow(false);

View File

@ -83,24 +83,14 @@ export default createComponent({
label={express.address}
class={bem('search-item')}
border={false}
onClick={() => {
onSelect(express);
}}
onClick={() => onSelect(express)}
/>
));
};
const onFocus = (event: Event) => {
emit('focus', event);
};
const onBlur = (event: Event) => {
emit('blur', event);
};
const onInput = (value: string) => {
emit('input', value);
};
const onBlur = (event: Event) => emit('blur', event);
const onFocus = (event: Event) => emit('focus', event);
const onInput = (value: string) => emit('input', value);
return () => {
if (props.show) {

View File

@ -239,12 +239,8 @@ export default createComponent({
Dialog.confirm({
title: t('confirmDelete'),
})
.then(() => {
emit('delete', state.data);
})
.catch(() => {
emit('cancel-delete', state.data);
});
.then(() => emit('delete', state.data))
.catch(() => emit('cancel-delete', state.data));
};
// get values of area component
@ -277,9 +273,7 @@ export default createComponent({
<Switch
v-model={state.data.isDefault}
size="24"
onChange={(event) => {
emit('change-default', event);
}}
onChange={(event) => emit('change-default', event)}
/>
),
};
@ -306,9 +300,7 @@ export default createComponent({
watch(
() => props.areaList,
() => {
setAreaCode(state.data.areaCode);
}
() => setAreaCode(state.data.areaCode)
);
watch(
@ -378,9 +370,7 @@ export default createComponent({
onBlur={onDetailBlur}
onFocus={() => onFocus('addressDetail')}
onInput={onChangeDetail}
onSelect-search={(event: Event) => {
emit('select-search', event);
}}
onSelect-search={(event: Event) => emit('select-search', event)}
/>
{props.showPostal && (
<Field

View File

@ -51,9 +51,7 @@ export default createComponent({
emit(name, item, index);
};
const onClick = () => {
emit('click-item', item, index);
};
const onClick = () => emit('click-item', item, index);
const onSelect = () => {
const name = disabled ? 'select-disabled' : 'select';
@ -87,24 +85,18 @@ export default createComponent({
}
};
const renderBottom = () => {
const onClick = () => {
emit('add');
};
return (
<div class={bem('bottom')}>
<Button
round
block
type="danger"
text={props.addButtonText || t('add')}
class={bem('add')}
onClick={onClick}
/>
</div>
);
};
const renderBottom = () => (
<div class={bem('bottom')}>
<Button
round
block
type="danger"
text={props.addButtonText || t('add')}
class={bem('add')}
onClick={() => emit('add')}
/>
</div>
);
return () => {
const List = renderList(props.list);

View File

@ -294,9 +294,7 @@ export default createComponent({
watch(
() => props.columnsNum,
() => {
nextTick(setValues);
}
() => nextTick(setValues)
);
useExpose({ reset, getArea, getValues });

View File

@ -237,9 +237,7 @@ export default createComponent({
color={props.color}
offset={offset.value}
rowHeight={rowHeight.value}
onClick={(item) => {
emit('click', item);
}}
onClick={(item) => emit('click', item)}
/>
);

View File

@ -332,9 +332,7 @@ export default createComponent({
return true;
};
const onConfirm = () => {
emit('confirm', copyDates(state.currentDate));
};
const onConfirm = () => emit('confirm', copyDates(state.currentDate));
const select = (date: Date | Date[], complete?: boolean) => {
const setCurrentDate = (date: Date | Date[]) => {
@ -426,9 +424,7 @@ export default createComponent({
}
};
const togglePopup = (value: boolean) => {
emit('update:show', value);
};
const togglePopup = (value: boolean) => emit('update:show', value);
const renderMonth = (date: Date, index: number) => {
const showMonthTitle = index !== 0 || !props.showSubtitle;

View File

@ -80,9 +80,7 @@ export default createComponent({
<a
href={props.thumbLink}
class={bem('thumb')}
onClick={(event) => {
emit('click-thumb', event);
}}
onClick={(event: MouseEvent) => emit('click-thumb', event)}
>
{renderThumbImage()}
{renderThumbTag()}

View File

@ -172,9 +172,7 @@ export default createComponent({
}
};
const onClose = () => {
emit('close');
};
const onClose = () => emit('close');
const renderHeader = () => (
<div class={bem('header')}>
@ -200,9 +198,7 @@ export default createComponent({
<li
class={bem('option', { selected: isSelected })}
style={{ color: isSelected ? props.activeColor : undefined }}
onClick={() => {
onSelect(option, tabIndex);
}}
onClick={() => onSelect(option, tabIndex)}
>
<span>{option[textKey]}</span>
{isSelected ? (

View File

@ -69,9 +69,7 @@ export default createComponent({
watch(
() => props.modelValue,
(value) => {
emit('change', value);
}
(value) => emit('change', value)
);
useExpose({ toggleAll });

View File

@ -67,9 +67,7 @@ export default createComponent({
watch(
() => props.modelValue,
(value) => {
emit('change', value);
}
(value) => emit('change', value)
);
useExpose({ toggle, props, checked });

View File

@ -59,9 +59,7 @@ export default createComponent({
const onDelete = () => {
Dialog.confirm({
title: t('confirmDelete'),
}).then(() => {
emit('delete', contact);
});
}).then(() => emit('delete', contact));
};
const renderButtons = () => (
@ -90,9 +88,7 @@ export default createComponent({
<Switch
v-model={contact.isDefault}
size={24}
onChange={(checked: boolean) => {
emit('change-default', checked);
}}
onChange={(checked: boolean) => emit('change-default', checked)}
/>
);

View File

@ -96,9 +96,7 @@ export default createComponent({
type="danger"
class={bem('add')}
text={props.addText || t('addText')}
onClick={() => {
emit('add');
}}
onClick={() => emit('add')}
/>
</div>
</div>

View File

@ -207,9 +207,7 @@ export default createComponent({
watch(
() => state.code,
(value) => {
emit('update:code', value);
}
(value) => emit('update:code', value)
);
watch(() => props.displayedCouponIndex, scrollToCoupon);
@ -233,9 +231,7 @@ export default createComponent({
type="danger"
class={bem('close')}
text={props.closeButtonText || t('close')}
onClick={() => {
emit('change', -1);
}}
onClick={() => emit('change', -1)}
/>
</div>
</div>

View File

@ -60,7 +60,7 @@ export default createComponent({
);
return new Date(timestamp);
}
return undefined;
};
@ -270,16 +270,12 @@ export default createComponent({
emit('confirm', currentDate.value);
};
const onCancel = () => {
emit('cancel');
};
const onCancel = () => emit('cancel');
const onChange = () => {
updateInnerValue();
nextTick(() => {
nextTick(() => {
emit('change', currentDate.value);
});
nextTick(() => emit('change', currentDate.value));
});
};
@ -290,9 +286,9 @@ export default createComponent({
watch(columns, updateColumnValue);
watch(currentDate, (value, oldValue) => {
emit('update:modelValue', oldValue ? value : null);
});
watch(currentDate, (value, oldValue) =>
emit('update:modelValue', oldValue ? value : null)
);
watch(
[() => props.filter, () => props.minDate, () => props.maxDate],

View File

@ -119,21 +119,13 @@ export default createComponent({
updateColumnValue();
};
const onConfirm = () => {
emit('confirm', currentDate.value);
};
const onCancel = () => {
emit('cancel');
};
const onConfirm = () => emit('confirm', currentDate.value);
const onCancel = () => emit('cancel');
const onChange = () => {
updateInnerValue();
nextTick(() => {
nextTick(() => {
emit('change', currentDate.value);
});
nextTick(() => emit('change', currentDate.value));
});
};
@ -155,9 +147,7 @@ export default createComponent({
updateInnerValue
);
watch(currentDate, (value) => {
emit('update:modelValue', value);
});
watch(currentDate, (value) => emit('update:modelValue', value));
watch(
() => props.modelValue,

View File

@ -64,9 +64,7 @@ export default createComponent({
cancel: false,
});
const onUpdateShow = (value: boolean) => {
emit('update:show', value);
};
const onUpdateShow = (value: boolean) => emit('update:show', value);
const close = (action: DialogAction) => {
onUpdateShow(false);

View File

@ -64,11 +64,10 @@ export default createComponent({
return;
}
const createEmitter = (eventName: 'open' | 'close' | 'opened') => () =>
emit(eventName);
const onOpen = createEmitter('open');
const onClose = createEmitter('close');
const onOpened = createEmitter('opened');
const getEmitter = (name: 'open' | 'close' | 'opened') => () => emit(name);
const onOpen = getEmitter('open');
const onClose = getEmitter('close');
const onOpened = getEmitter('opened');
const onClosed = () => {
state.showWrapper = false;

View File

@ -330,17 +330,13 @@ export default createComponent({
resetScroll();
};
const onClickInput = (event: MouseEvent) => {
emit('click-input', event);
};
const onClickInput = (event: MouseEvent) => emit('click-input', event);
const onClickLeftIcon = (event: MouseEvent) => {
const onClickLeftIcon = (event: MouseEvent) =>
emit('click-left-icon', event);
};
const onClickRightIcon = (event: MouseEvent) => {
const onClickRightIcon = (event: MouseEvent) =>
emit('click-right-icon', event);
};
const onClear = (event: MouseEvent) => {
preventDefault(event);

View File

@ -156,9 +156,7 @@ export default createComponent({
const values = getValues();
validate()
.then(() => {
emit('submit', values);
})
.then(() => emit('submit', values))
.catch((errors: FieldValidateError[]) => {
emit('failed', { values, errors });

View File

@ -16,6 +16,11 @@ import ImagePreviewItem from './ImagePreviewItem';
const [createComponent, bem] = createNamespace('image-preview');
export type ImagePreviewScaleEventParams = {
scale: number;
index: number;
};
export default createComponent({
props: {
show: Boolean,
@ -90,21 +95,16 @@ export default createComponent({
}
};
const emitScale = (args: { scale: number; index: number }) => {
const emitScale = (args: ImagePreviewScaleEventParams) =>
emit('scale', args);
};
const toggle = (show: boolean) => {
emit('update:show', show);
};
const toggle = (show: boolean) => emit('update:show', show);
const emitClose = () => {
callInterceptor({
interceptor: props.beforeClose,
args: [state.active],
done: () => {
toggle(false);
},
done: () => toggle(false),
});
};
@ -174,9 +174,7 @@ export default createComponent({
}
};
const onClosed = () => {
emit('closed');
};
const onClosed = () => emit('closed');
const swipeTo = (index: number, options?: SwipeToOptions) => {
if (swipeRef.value) {

View File

@ -173,9 +173,7 @@ export default createComponent({
}
};
const init = () => {
nextTick(onScroll);
};
const init = () => nextTick(onScroll);
useEventListener('scroll', onScroll, { target: scrollParent });

View File

@ -34,13 +34,8 @@ export default createComponent({
const navBarRef = ref<HTMLElement>();
const renderPlaceholder = usePlaceholder(navBarRef, bem);
const onClickLeft = (event: MouseEvent) => {
emit('click-left', event);
};
const onClickRight = (event: MouseEvent) => {
emit('click-right', event);
};
const onClickLeft = (event: MouseEvent) => emit('click-left', event);
const onClickRight = (event: MouseEvent) => emit('click-right', event);
const renderLeft = () => {
if (slots.left) {

View File

@ -146,9 +146,7 @@ export default createComponent({
}
};
const onAnimationEnd = () => {
emit(props.show ? 'show' : 'hide');
};
const onAnimationEnd = () => emit(props.show ? 'show' : 'hide');
const onPress = (text: string, type: KeyType) => {
if (text === '') {

View File

@ -144,9 +144,7 @@ export default createComponent({
const value = props.modelValue;
const simple = props.mode !== 'multi';
const onSelect = (value: number) => () => {
select(value, true);
};
const onSelect = (value: number) => () => select(value, true);
return (
<ul class={bem({ simple })}>

View File

@ -289,9 +289,7 @@ export default createComponent({
disabled,
selected: index === state.index,
}),
onClick: () => {
onClickItem(index);
},
onClick: () => onClickItem(index),
};
const childData = {

View File

@ -286,9 +286,7 @@ export default createComponent({
emitAction('confirm');
};
const cancel = () => {
emitAction('cancel');
};
const cancel = () => emitAction('cancel');
const renderTitle = () => {
if (slots.title) {
@ -342,9 +340,7 @@ export default createComponent({
swipeDuration={props.swipeDuration}
initialOptions={item[valuesKey]}
visibleItemCount={props.visibleItemCount}
onChange={() => {
onChange(columnIndex);
}}
onChange={() => onChange(columnIndex)}
/>
));

View File

@ -125,9 +125,7 @@ export default createComponent({
});
};
const toggle = (value: boolean) => {
emit('update:show', value);
};
const toggle = (value: boolean) => emit('update:show', value);
const onClickWrapper = () => {
if (props.trigger === 'click') {
@ -152,9 +150,7 @@ export default createComponent({
}
};
const onClickAway = () => {
toggle(false);
};
const onClickAway = () => toggle(false);
const renderAction = (action: PopoverAction, index: number) => {
const { icon, text, color, disabled, className } = action;

View File

@ -179,9 +179,7 @@ export default createComponent({
emit('update:modelValue', true);
// ensure value change can be watched
nextTick(() => {
emit('refresh');
});
nextTick(() => emit('refresh'));
} else {
setStatus(0);
}

View File

@ -29,15 +29,12 @@ export default createComponent({
setup(props, { emit, slots }) {
const { linkChildren } = useChildren(RADIO_KEY);
const updateModelValue = (value: unknown) => {
const updateModelValue = (value: unknown) =>
emit('update:modelValue', value);
};
watch(
() => props.modelValue,
(value) => {
emit('change', value);
}
(value) => emit('change', value)
);
linkChildren({

View File

@ -120,9 +120,7 @@ export default createComponent({
class: null,
};
const onInput = (value: string) => {
emit('update:modelValue', value);
};
const onInput = (value: string) => emit('update:modelValue', value);
return (
<Field

View File

@ -65,18 +65,15 @@ export default createComponent({
emits: ['cancel', 'select', 'update:show'],
setup(props, { emit, slots }) {
const toggle = (value: boolean) => {
emit('update:show', value);
};
const toggle = (value: boolean) => emit('update:show', value);
const onCancel = () => {
toggle(false);
emit('cancel');
};
const onSelect = (option: ShareSheetOption, index: number) => {
const onSelect = (option: ShareSheetOption, index: number) =>
emit('select', option, index);
};
const renderHeader = () => {
const title = slots.title ? slots.title() : props.title;
@ -103,9 +100,7 @@ export default createComponent({
role="button"
tabindex={0}
class={[bem('option'), className]}
onClick={() => {
onSelect(option, index);
}}
onClick={() => onSelect(option, index)}
>
<img src={getIconURL(icon)} class={bem('icon')} />
{name && <span class={bem('name')}>{name}</span>}

View File

@ -52,9 +52,7 @@ export default createComponent({
}
});
const onClickStep = () => {
parent.onClickStep(index.value);
};
const onClickStep = () => parent.onClickStep(index.value);
const renderCircle = () => {
const { finishIcon, activeIcon, activeColor, inactiveIcon } = parentProps;

View File

@ -46,9 +46,7 @@ export default createComponent({
setup(props, { emit, slots }) {
const { linkChildren } = useChildren(STEPS_KEY);
const onClickStep = (index: number) => {
emit('click-step', index);
};
const onClickStep = (index: number) => emit('click-step', index);
linkChildren({
props,

View File

@ -83,9 +83,7 @@ export default createComponent({
}
};
const onClickButton = () => {
emit('submit');
};
const onClickButton = () => emit('submit');
const renderButton = () => {
if (slots.button) {

View File

@ -147,9 +147,7 @@ export default createComponent({
position,
},
],
done: () => {
close(position);
},
done: () => close(position),
});
}
};
@ -186,13 +184,7 @@ export default createComponent({
close,
});
useClickAway(
root,
() => {
onClick('outside');
},
{ eventName: 'touchstart' }
);
useClickAway(root, () => onClick('outside'), { eventName: 'touchstart' });
return () => {
const wrapperStyle = {

View File

@ -297,9 +297,7 @@ export default createComponent({
autoplay();
};
const resize = () => {
initialize(state.active);
};
const resize = () => initialize(state.active);
let touchStartTime: number;
@ -454,9 +452,7 @@ export default createComponent({
});
onMounted(initialize);
onActivated(() => {
initialize(state.active);
});
onActivated(() => initialize(state.active));
onDeactivated(stopAutoplay);
onBeforeUnmount(stopAutoplay);

View File

@ -29,9 +29,7 @@ export default createComponent({
setup(props, { emit, slots }) {
const swipeRef = ref<ComponentInstance>();
const onChange = (index: number) => {
emit('change', index);
};
const onChange = (index: number) => emit('change', index);
const renderChildren = () => {
const Content = slots.default?.();

View File

@ -438,9 +438,8 @@ export default createComponent({
});
};
const onRendered = (name: string | number, title?: string) => {
const onRendered = (name: string | number, title?: string) =>
emit('rendered', name, title);
};
useExpose({
resize: setLine,

View File

@ -70,9 +70,7 @@ export default createComponent({
clearTimeout(timer);
};
const toggle = (show: boolean) => {
emit('update:show', show);
};
const toggle = (show: boolean) => emit('update:show', show);
const renderIcon = () => {
const { icon, type, iconPrefix, loadingType } = props;

View File

@ -56,15 +56,11 @@ export default defineComponent({
callInterceptor({
interceptor: beforeDelete,
args: [item, { name, index }],
done() {
emit('delete');
},
done: () => emit('delete'),
});
};
const onPreview = () => {
emit('preview');
};
const onPreview = () => emit('preview');
const renderDeleteIcon = () => {
if (props.deletable && props.item.status !== 'uploading') {

View File

@ -233,9 +233,7 @@ export default createComponent({
let imagePreview: ComponentInstance | undefined;
const onClosePreview = () => {
emit('close-preview');
};
const onClosePreview = () => emit('close-preview');
const previewImage = (item: FileListItem) => {
if (props.previewFullImage) {
@ -285,15 +283,9 @@ export default createComponent({
v-slots={{ 'preview-cover': slots['preview-cover'] }}
item={item}
index={index}
onClick={() => {
emit('click-preview', item, getDetail(index));
}}
onDelete={() => {
deleteFile(item, index);
}}
onPreview={() => {
previewImage(item);
}}
onClick={() => emit('click-preview', item, getDetail(index))}
onDelete={() => deleteFile(item, index)}
onPreview={() => previewImage(item)}
{...pick(props, ['name', 'lazyLoad'])}
{...previewData}
/>