[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
+1 -1
View File
@@ -36,7 +36,7 @@ function prefix(name: string, mods: Mods): Mods {
return ret;
}
export default (name: string) => (el?: Mods, mods?: Mods): Mods => {
export const useBEM = (name: string) => (el?: Mods, mods?: Mods): Mods => {
if (el && typeof el !== 'string') {
mods = el;
el = '';
+1 -1
View File
@@ -1,7 +1,7 @@
import { get, camelize } from '..';
import locale from '../../locale';
export default (name: string) => {
export const useI18N = (name: string) => {
const prefix = camelize(name) + '.';
return (path: string, ...args: any[]): string => {
const message = get(locale.messages(), prefix + path) || get(locale.messages(), path);
+7 -7
View File
@@ -1,14 +1,14 @@
import useBem from './bem';
import useSfc from './sfc';
import useI18n from './i18n';
import { useBEM } from './bem';
import { useSFC } from './sfc';
import { useI18N } from './i18n';
type UseReturn = [
ReturnType<typeof useSfc>,
ReturnType<typeof useBem>,
ReturnType<typeof useI18n>
ReturnType<typeof useSFC>,
ReturnType<typeof useBEM>,
ReturnType<typeof useI18N>
];
export function use(name: string): UseReturn {
name = 'van-' + name;
return [useSfc(name), useBem(name), useI18n(name)];
return [useSFC(name), useBEM(name), useI18N(name)];
}
+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) {