chore: use gen instead of render (#4922)

This commit is contained in:
neverland 2019-11-05 09:12:03 +08:00 committed by GitHub
parent 9c54a77845
commit 56e9b7afa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 46 additions and 46 deletions

View File

@ -30,7 +30,7 @@ export default createComponent({
this.$refs.field.blur(); this.$refs.field.blur();
}, },
renderFinish() { genFinish() {
const show = this.value && this.focused && android; const show = this.value && this.focused && android;
if (show) { if (show) {
return ( return (
@ -41,7 +41,7 @@ export default createComponent({
} }
}, },
renderSearchResult() { genSearchResult() {
const { searchResult } = this; const { searchResult } = this;
const show = this.focused && searchResult && this.showSearchResult; const show = this.focused && searchResult && this.showSearchResult;
if (show) { if (show) {
@ -75,10 +75,10 @@ export default createComponent({
label={t('label')} label={t('label')}
maxlength={this.detailMaxlength} maxlength={this.detailMaxlength}
placeholder={t('placeholder')} placeholder={t('placeholder')}
scopedSlots={{ icon: this.renderFinish }} scopedSlots={{ icon: this.genFinish }}
{...{ on: this.$listeners }} {...{ on: this.$listeners }}
/> />
{this.renderSearchResult()} {this.genSearchResult()}
</Cell> </Cell>
); );
} }

View File

@ -45,7 +45,7 @@ function AddressItem(
emit(ctx, 'click'); emit(ctx, 'click');
} }
const renderRightIcon = () => ( const genRightIcon = () => (
<Icon <Icon
name="edit" name="edit"
class={bem('edit')} class={bem('edit')}
@ -57,7 +57,7 @@ function AddressItem(
/> />
); );
const renderContent = () => { const genContent = () => {
const { data } = props; const { data } = props;
const Info = [ const Info = [
<div class={bem('name')}>{`${data.name}${data.tel}`}</div>, <div class={bem('name')}>{`${data.name}${data.tel}`}</div>,
@ -79,8 +79,8 @@ function AddressItem(
valueClass={bem('value')} valueClass={bem('value')}
clickable={switchable && !disabled} clickable={switchable && !disabled}
scopedSlots={{ scopedSlots={{
default: renderContent, default: genContent,
'right-icon': renderRightIcon 'right-icon': genRightIcon
}} }}
onClick={onClick} onClick={onClick}
{...inherit(ctx)} {...inherit(ctx)}

View File

@ -29,7 +29,7 @@ function AddressList(
slots: AddressListSlots, slots: AddressListSlots,
ctx: RenderContext<AddressListProps> ctx: RenderContext<AddressListProps>
) { ) {
function renderList(list?: AddressItemData[], disabled?: boolean) { function genList(list?: AddressItemData[], disabled?: boolean) {
if (!list) { if (!list) {
return; return;
} }
@ -57,8 +57,8 @@ function AddressList(
)); ));
} }
const List = renderList(props.list); const List = genList(props.list);
const DisabledList = renderList(props.disabledList, true); const DisabledList = genList(props.disabledList, true);
return ( return (
<div class={bem()} {...inherit(ctx)}> <div class={bem()} {...inherit(ctx)}>

View File

@ -127,7 +127,7 @@ export default createComponent({
}); });
}, },
renderEmpty() { genEmpty() {
return ( return (
<div class={bem('empty')}> <div class={bem('empty')}>
<img src={this.emptyImage} /> <img src={this.emptyImage} />
@ -136,7 +136,7 @@ export default createComponent({
); );
}, },
renderExchangeButton() { genExchangeButton() {
return ( return (
<Button <Button
size="small" size="small"
@ -167,7 +167,7 @@ export default createComponent({
placeholder={this.inputPlaceholder || t('placeholder')} placeholder={this.inputPlaceholder || t('placeholder')}
maxlength="20" maxlength="20"
scopedSlots={{ scopedSlots={{
button: this.renderExchangeButton button: this.genExchangeButton
}} }}
/> />
); );
@ -187,7 +187,7 @@ export default createComponent({
nativeOnClick={onChange(index)} nativeOnClick={onChange(index)}
/> />
))} ))}
{!coupons.length && this.renderEmpty()} {!coupons.length && this.genEmpty()}
</div> </div>
</Tab> </Tab>
); );
@ -198,7 +198,7 @@ export default createComponent({
{disabledCoupons.map(coupon => ( {disabledCoupons.map(coupon => (
<Coupon disabled key={coupon.id} coupon={coupon} currency={this.currency} /> <Coupon disabled key={coupon.id} coupon={coupon} currency={this.currency} />
))} ))}
{!disabledCoupons.length && this.renderEmpty()} {!disabledCoupons.length && this.genEmpty()}
</div> </div>
</Tab> </Tab>
); );

View File

@ -202,7 +202,7 @@ export default createComponent({
} }
}, },
renderInput() { genInput() {
const inputSlot = this.slots('input'); const inputSlot = this.slots('input');
if (inputSlot) { if (inputSlot) {
@ -240,7 +240,7 @@ export default createComponent({
return <input type={this.type} {...inputProps} />; return <input type={this.type} {...inputProps} />;
}, },
renderLeftIcon() { genLeftIcon() {
const showLeftIcon = this.slots('left-icon') || this.leftIcon; const showLeftIcon = this.slots('left-icon') || this.leftIcon;
if (showLeftIcon) { if (showLeftIcon) {
return ( return (
@ -251,7 +251,7 @@ export default createComponent({
} }
}, },
renderRightIcon() { genRightIcon() {
const { slots } = this; const { slots } = this;
const showRightIcon = slots('right-icon') || this.rightIcon; const showRightIcon = slots('right-icon') || this.rightIcon;
if (showRightIcon) { if (showRightIcon) {
@ -263,7 +263,7 @@ export default createComponent({
} }
}, },
renderWordLimit() { genWordLimit() {
if (this.showWordLimit && this.$attrs.maxlength) { if (this.showWordLimit && this.$attrs.maxlength) {
return ( return (
<div class={bem('word-limit')}> <div class={bem('word-limit')}>
@ -278,7 +278,7 @@ export default createComponent({
const { slots, labelAlign } = this; const { slots, labelAlign } = this;
const scopedSlots = { const scopedSlots = {
icon: this.renderLeftIcon icon: this.genLeftIcon
}; };
if (slots('label')) { if (slots('label')) {
scopedSlots.title = () => slots('label'); scopedSlots.title = () => slots('label');
@ -306,14 +306,14 @@ export default createComponent({
onClick={this.onClick} onClick={this.onClick}
> >
<div class={bem('body')}> <div class={bem('body')}>
{this.renderInput()} {this.genInput()}
{this.showClear && ( {this.showClear && (
<Icon name="clear" class={bem('clear')} onTouchstart={this.onClear} /> <Icon name="clear" class={bem('clear')} onTouchstart={this.onClear} />
)} )}
{this.renderRightIcon()} {this.genRightIcon()}
{slots('button') && <div class={bem('button')}>{slots('button')}</div>} {slots('button') && <div class={bem('button')}>{slots('button')}</div>}
</div> </div>
{this.renderWordLimit()} {this.genWordLimit()}
{this.errorMessage && ( {this.errorMessage && (
<div class={bem('error-message', this.errorMessageAlign)}> <div class={bem('error-message', this.errorMessageAlign)}>
{this.errorMessage} {this.errorMessage}

View File

@ -104,7 +104,7 @@ export default createComponent({
this.$emit('click', event); this.$emit('click', event);
}, },
renderPlaceholder() { genPlaceholder() {
if (this.loading && this.showLoading) { if (this.loading && this.showLoading) {
return ( return (
<div class={bem('loading')}> <div class={bem('loading')}>
@ -122,7 +122,7 @@ export default createComponent({
} }
}, },
renderImage() { genImage() {
const imgData = { const imgData = {
class: bem('img'), class: bem('img'),
attrs: { attrs: {
@ -150,8 +150,8 @@ export default createComponent({
render() { render() {
return ( return (
<div class={bem({ round: this.round })} style={this.style} onClick={this.onClick}> <div class={bem({ round: this.round })} style={this.style} onClick={this.onClick}>
{this.renderImage()} {this.genImage()}
{this.renderPlaceholder()} {this.genPlaceholder()}
</div> </div>
); );
} }

View File

@ -136,7 +136,7 @@ export default createComponent({
return this.allowHalf ? 0.5 : 1; return this.allowHalf ? 0.5 : 1;
}, },
renderStar(status, index) { genStar(status, index) {
const { icon, color, count, voidIcon, disabled, voidColor, disabledColor } = this; const { icon, color, count, voidIcon, disabled, voidColor, disabledColor } = this;
const score = index + 1; const score = index + 1;
const isFull = status === 'full'; const isFull = status === 'full';
@ -196,7 +196,7 @@ export default createComponent({
onTouchstart={this.onTouchStart} onTouchstart={this.onTouchStart}
onTouchmove={this.onTouchMove} onTouchmove={this.onTouchMove}
> >
{this.list.map((status, index) => this.renderStar(status, index))} {this.list.map((status, index) => this.genStar(status, index))}
</div> </div>
); );
} }

View File

@ -44,7 +44,7 @@ export default createComponent({
this.$toast(t('oversize', this.maxSize)); this.$toast(t('oversize', this.maxSize));
}, },
renderUploader(content, disabled = false) { genUploader(content, disabled = false) {
return ( return (
<Uploader <Uploader
class={bem('uploader')} class={bem('uploader')}
@ -60,7 +60,7 @@ export default createComponent({
); );
}, },
renderMask() { genMask() {
return ( return (
<div class={bem('mask')}> <div class={bem('mask')}>
{this.uploadFail {this.uploadFail
@ -80,7 +80,7 @@ export default createComponent({
render() { render() {
return ( return (
<div class={bem()}> <div class={bem()}>
{this.value && this.renderUploader( {this.value && this.genUploader(
[ [
<img src={this.value} />, <img src={this.value} />,
<Icon <Icon
@ -94,15 +94,15 @@ export default createComponent({
true true
)} )}
{this.paddingImg && this.renderUploader( {this.paddingImg && this.genUploader(
[ [
<img src={this.paddingImg} />, <img src={this.paddingImg} />,
this.renderMask() this.genMask()
], ],
!this.uploadFail !this.uploadFail
)} )}
{!this.value && !this.paddingImg && this.renderUploader( {!this.value && !this.paddingImg && this.genUploader(
<div class={bem('trigger')}> <div class={bem('trigger')}>
<Icon name="photograph" size="22px" /> <Icon name="photograph" size="22px" />
</div> </div>

View File

@ -312,7 +312,7 @@ export default createComponent({
} }
}, },
renderIndicator() { genIndicator() {
const { count, activeIndicator } = this; const { count, activeIndicator } = this;
const slot = this.slots('indicator'); const slot = this.slots('indicator');
@ -349,7 +349,7 @@ export default createComponent({
> >
{this.slots()} {this.slots()}
</div> </div>
{this.renderIndicator()} {this.genIndicator()}
</div> </div>
); );
} }

View File

@ -53,7 +53,7 @@ export default createComponent({
} }
}, },
renderChildren() { genChildren() {
if (this.animated) { if (this.animated) {
return ( return (
<div class={bem('track')} style={this.style}> <div class={bem('track')} style={this.style}>
@ -72,7 +72,7 @@ export default createComponent({
class={bem('content', { animated: this.animated })} class={bem('content', { animated: this.animated })}
{...{ on: this.listeners }} {...{ on: this.listeners }}
> >
{this.renderChildren()} {this.genChildren()}
</div> </div>
); );
} }

View File

@ -213,7 +213,7 @@ export default createComponent({
} }
}, },
renderPreviewItem(item, index) { genPreviewItem(item, index) {
const DeleteIcon = ( const DeleteIcon = (
<Icon <Icon
name="clear" name="clear"
@ -265,13 +265,13 @@ export default createComponent({
); );
}, },
renderPreviewList() { genPreviewList() {
if (this.previewImage) { if (this.previewImage) {
return this.fileList.map(this.renderPreviewItem); return this.fileList.map(this.genPreviewItem);
} }
}, },
renderUpload() { genUpload() {
if (this.fileList.length >= this.maxCount) { if (this.fileList.length >= this.maxCount) {
return; return;
} }
@ -322,8 +322,8 @@ export default createComponent({
return ( return (
<div class={bem()}> <div class={bem()}>
<div class={bem('wrapper')}> <div class={bem('wrapper')}>
{this.renderPreviewList()} {this.genPreviewList()}
{this.renderUpload()} {this.genUpload()}
</div> </div>
</div> </div>
); );