[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'); const [sfc, bem] = use('button');
export default sfc( export default sfc({
{ functional: true,
props: { props: {
text: String, text: String,
block: Boolean, block: Boolean,
@ -67,6 +68,4 @@ export default sfc(
</props.tag> </props.tag>
); );
} }
}, });
true
);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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