[improvement] unify mixin name (#2795)

This commit is contained in:
neverland
2019-02-19 16:04:29 +08:00
committed by GitHub
parent 8c6ab91f6d
commit 9d0255d9e1
49 changed files with 112 additions and 122 deletions
+9 -7
View File
@@ -3,7 +3,7 @@
*/
import '../../locale';
import { camelize } from '..';
import SlotsMixin from '../../mixins/slots';
import { SlotsMixin } from '../../mixins/slots';
import Vue, {
VueConstructor,
ComponentOptions,
@@ -35,7 +35,7 @@ export interface VantComponentOptions extends ComponentOptions<Vue> {
export type DefaultProps = Record<string, any>;
export type FunctionalComponent<
export type FunctionComponent<
Props = DefaultProps,
PropDefs = PropsDefinition<Props>
> = {
@@ -93,6 +93,7 @@ function install(this: ComponentOptions<Vue>, Vue: VueConstructor) {
// unify slots & scopedSlots
export function unifySlots(context: RenderContext) {
// use data.scopedSlots in lower Vue version
const scopedSlots = context.scopedSlots || context.data.scopedSlots || {};
const slots = context.slots();
@@ -105,8 +106,9 @@ export function unifySlots(context: RenderContext) {
return scopedSlots;
}
function transformFunctionalComponent(
pure: FunctionalComponent
// should be removed after Vue 3
function transformFunctionComponent(
pure: FunctionComponent
): VantComponentOptions {
return {
functional: true,
@@ -117,11 +119,11 @@ function transformFunctionalComponent(
};
}
export default (name: string) => <Props = DefaultProps, Events = {}, Slots = {}>(
sfc: VantComponentOptions | FunctionalComponent
export const useSFC = (name: string) => <Props = DefaultProps, Events = {}, Slots = {}>(
sfc: VantComponentOptions | FunctionComponent
): TsxComponent<Props, Events, Slots> => {
if (typeof sfc === 'function') {
sfc = transformFunctionalComponent(sfc);
sfc = transformFunctionComponent(sfc);
}
if (!sfc.functional) {