[improvement] declare functional sfc (#2695)

This commit is contained in:
neverland 2019-02-06 21:11:12 +08:00 committed by GitHub
parent 061382014d
commit 1b60e4df80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 465 additions and 494 deletions

View File

@ -3,8 +3,9 @@ import Loading from '../loading';
const [sfc, bem] = use('button');
export default sfc(
{
export default sfc({
functional: true,
props: {
text: String,
block: Boolean,
@ -67,6 +68,4 @@ export default sfc(
</props.tag>
);
}
},
true
);
});

View File

@ -2,8 +2,9 @@ import { use } from '../utils';
const [sfc, bem] = use('cell-group');
export default sfc(
{
export default sfc({
functional: true,
props: {
border: {
type: Boolean,
@ -13,14 +14,9 @@ export default sfc(
render(h, context) {
return (
<div
class={[bem(), { 'van-hairline--top-bottom': context.props.border }]}
{...context.data}
>
<div class={[bem(), { 'van-hairline--top-bottom': context.props.border }]} {...context.data}>
{context.children}
</div>
);
}
},
true
);
});

View File

@ -7,8 +7,9 @@ import RadioGroup from '../radio-group';
const [sfc, bem, t] = use('contact-list');
export default sfc(
{
export default sfc({
functional: true,
props: {
value: null,
list: Array,
@ -58,6 +59,4 @@ export default sfc(
</div>
);
}
},
true
);
});

View File

@ -2,8 +2,9 @@ import { use } from '../utils';
const [sfc, bem] = use('goods-action');
export default sfc(
{
export default sfc({
functional: true,
render(h, context) {
return (
<div class={bem()} {...context.data}>
@ -11,6 +12,4 @@ export default sfc(
</div>
);
}
},
true
);
});

View File

@ -4,8 +4,9 @@ import isSrc from '../utils/validate/src';
const [sfc] = use('icon');
export default sfc(
{
export default sfc({
functional: true,
props: {
name: String,
size: String,
@ -39,6 +40,4 @@ export default sfc(
</i>
);
}
},
true
);
});

View File

@ -2,8 +2,9 @@ import { use, isDef } from '../utils';
const [sfc, bem] = use('info');
export default sfc(
{
export default sfc({
functional: true,
props: {
info: [String, Number]
},
@ -17,6 +18,4 @@ export default sfc(
)
);
}
},
true
);
});

View File

@ -3,8 +3,9 @@ import { use } from '../utils';
const [sfc, bem] = use('loading');
const DEFAULT_COLOR = '#c9c9c9';
export default sfc(
{
export default sfc({
functional: true,
props: {
size: String,
type: {
@ -50,6 +51,4 @@ export default sfc(
</div>
);
}
},
true
);
});

View File

@ -3,8 +3,9 @@ import Icon from '../icon';
const [sfc, bem] = use('nav-bar');
export default sfc(
{
export default sfc({
functional: true,
props: {
title: String,
fixed: Boolean,
@ -31,25 +32,17 @@ export default sfc(
style={{ zIndex: props.zIndex }}
{...inherit}
>
<div
class={bem('left')}
onClick={listeners['click-left'] || noop}
>
<div class={bem('left')} onClick={listeners['click-left'] || noop}>
{slots.left || [
props.leftArrow && <Icon class={bem('arrow')} name="arrow-left" />,
props.leftText && <span class={bem('text')}>{props.leftText}</span>
]}
</div>
<div class={[bem('title'), 'van-ellipsis']}>{slots.title || props.title}</div>
<div
class={bem('right')}
onClick={listeners['click-right'] || noop}
>
<div class={bem('right')} onClick={listeners['click-right'] || noop}>
{slots.right || (props.rightText && <span class={bem('text')}>{props.rightText}</span>)}
</div>
</div>
);
}
},
true
);
});

View File

@ -4,8 +4,9 @@ import CellGroup from '../cell-group';
const [sfc, bem] = use('panel');
export default sfc(
{
export default sfc({
functional: true,
props: {
icon: String,
desc: String,
@ -33,6 +34,4 @@ export default sfc(
</CellGroup>
);
}
},
true
);
});

View File

@ -2,8 +2,9 @@ import { use } from '../utils';
const [sfc, bem] = use('password-input');
export default sfc(
{
export default sfc({
functional: true,
props: {
info: String,
errorInfo: String,
@ -46,6 +47,4 @@ export default sfc(
</div>
);
}
},
true
);
});

View File

@ -3,8 +3,9 @@ import Button from '../button';
const [sfc, bem, t] = use('submit-bar');
export default sfc(
{
export default sfc({
functional: true,
props: {
tip: String,
label: String,
@ -61,6 +62,4 @@ export default sfc(
</div>
);
}
},
true
);
});

View File

@ -5,8 +5,9 @@ import SwitchMixin from '../mixins/switch';
const [sfc, bem] = use('switch-cell');
export default sfc(
{
export default sfc({
functional: true,
mixins: [SwitchMixin],
props: {
@ -22,17 +23,9 @@ export default sfc(
const { props } = context;
return (
<Cell
center
title={props.title}
border={props.border}
class={bem()}
{...inherit}
>
<Cell center title={props.title} border={props.border} class={bem()} {...inherit}>
<Switch {...{ props, on: context.listeners }} />
</Cell>
);
}
},
true
);
});

View File

@ -9,8 +9,9 @@ const COLOR_MAP = {
success: GREEN
};
export default sfc(
{
export default sfc({
functional: true,
props: {
size: String,
type: String,
@ -48,6 +49,4 @@ export default sfc(
</span>
);
}
},
true
);
});

View File

@ -36,7 +36,6 @@ const mapInheritKey = { nativeOn: 'on' };
function functional(sfc) {
const { render } = sfc;
sfc.functional = true;
sfc.render = (h, context) => {
const inherit = inheritKey.reduce((obj, key) => {
if (context.data[key]) {
@ -48,7 +47,7 @@ function functional(sfc) {
};
}
export default name => (sfc, isFunctional) => {
export default name => sfc => {
sfc.name = name;
sfc.install = install;
sfc.mixins = sfc.mixins || [];
@ -58,7 +57,7 @@ export default name => (sfc, isFunctional) => {
defaultProps(sfc.props);
}
if (isFunctional) {
if (sfc.functional) {
functional(sfc);
}