perf(hooks): [use-namespace] simplify code (#9298)

This commit is contained in:
zz 2022-09-01 23:20:32 +08:00 committed by GitHub
parent 8fb1d458df
commit f0414c7822
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,3 @@
import { computed, unref } from 'vue'
import { useGlobalConfig } from '../use-global-config' import { useGlobalConfig } from '../use-global-config'
export const defaultNamespace = 'el' export const defaultNamespace = 'el'
@ -25,29 +24,28 @@ const _bem = (
} }
export const useNamespace = (block: string) => { export const useNamespace = (block: string) => {
const globalConfig = useGlobalConfig('namespace') const namespace = useGlobalConfig('namespace', defaultNamespace)
const namespace = computed(() => globalConfig.value || defaultNamespace)
const b = (blockSuffix = '') => const b = (blockSuffix = '') =>
_bem(unref(namespace), block, blockSuffix, '', '') _bem(namespace.value, block, blockSuffix, '', '')
const e = (element?: string) => const e = (element?: string) =>
element ? _bem(unref(namespace), block, '', element, '') : '' element ? _bem(namespace.value, block, '', element, '') : ''
const m = (modifier?: string) => const m = (modifier?: string) =>
modifier ? _bem(unref(namespace), block, '', '', modifier) : '' modifier ? _bem(namespace.value, block, '', '', modifier) : ''
const be = (blockSuffix?: string, element?: string) => const be = (blockSuffix?: string, element?: string) =>
blockSuffix && element blockSuffix && element
? _bem(unref(namespace), block, blockSuffix, element, '') ? _bem(namespace.value, block, blockSuffix, element, '')
: '' : ''
const em = (element?: string, modifier?: string) => const em = (element?: string, modifier?: string) =>
element && modifier element && modifier
? _bem(unref(namespace), block, '', element, modifier) ? _bem(namespace.value, block, '', element, modifier)
: '' : ''
const bm = (blockSuffix?: string, modifier?: string) => const bm = (blockSuffix?: string, modifier?: string) =>
blockSuffix && modifier blockSuffix && modifier
? _bem(unref(namespace), block, blockSuffix, '', modifier) ? _bem(namespace.value, block, blockSuffix, '', modifier)
: '' : ''
const bem = (blockSuffix?: string, element?: string, modifier?: string) => const bem = (blockSuffix?: string, element?: string, modifier?: string) =>
blockSuffix && element && modifier blockSuffix && element && modifier
? _bem(unref(namespace), block, blockSuffix, element, modifier) ? _bem(namespace.value, block, blockSuffix, element, modifier)
: '' : ''
const is: { const is: {
(name: string, state: boolean | undefined): string (name: string, state: boolean | undefined): string