[improvement] make props less magic (#3775)

This commit is contained in:
neverland
2019-07-08 16:18:19 +08:00
committed by GitHub
parent 642639da6e
commit be96fa2233
55 changed files with 283 additions and 206 deletions
-24
View File
@@ -25,26 +25,6 @@ export type TsxComponent<Props, Events, Slots> = (
props: Partial<Props & Events & TsxBaseProps<Slots>>
) => VNode;
const arrayProp = {
type: Array,
default: () => []
};
const numberProp = {
type: Number,
default: 0
};
function defaultProps(props: any) {
Object.keys(props).forEach(key => {
if (props[key] === Array) {
props[key] = arrayProp;
} else if (props[key] === Number) {
props[key] = numberProp;
}
});
}
function install(this: ComponentOptions<Vue>, Vue: VueConstructor) {
const { name } = this;
Vue.component(name as string, this);
@@ -89,10 +69,6 @@ export function createComponent(name: string) {
sfc.mixins.push(SlotsMixin);
}
if (sfc.props) {
defaultProps(sfc.props);
}
sfc.name = name;
sfc.install = install;