Skip to content

Commit

Permalink
fix(ConfigProvider): 修复 config-provider 同时存在 provide 和 setup#provide …
Browse files Browse the repository at this point in the history
…导致卡顿的性能问题
  • Loading branch information
Ryqsky committed Jul 2, 2022
1 parent 89a7ced commit 1ffbd38
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
10 changes: 1 addition & 9 deletions src/config-provider/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Vue, { PropType, VNode } from 'vue';
import cloneDeep from 'lodash/cloneDeep';
import { provide, computed } from '@vue/composition-api';
import { GlobalConfigProvider } from './type';
import { configProviderInjectKey, defaultGlobalConfig, mergeWith } from './context';
import { defaultGlobalConfig, mergeWith } from './context';

const ConfigProvider = Vue.extend({
name: 'TConfigProvider',
Expand All @@ -29,14 +29,6 @@ const ConfigProvider = Vue.extend({
},
},

setup(props) {
const defaultData = cloneDeep(defaultGlobalConfig);
provide(
configProviderInjectKey,
computed(() => mergeWith(defaultData, props.globalConfig)),
);
},

render(): VNode {
if (this.$slots.default.length === 1) {
return this.$slots.default[0];
Expand Down
2 changes: 0 additions & 2 deletions src/config-provider/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export type Locale = typeof defaultZhCN;
// 导出全局配置(包括语言配置)全部类型
export * from './type';

export const configProviderInjectKey: InjectionKey<ComputedRef<GlobalConfigProvider>> = Symbol('configProvide');

// deal with https://github.com/lodash/lodash/issues/1313
export const mergeWith = (defaultGlobalConfig: GlobalConfigProvider, injectConfig: GlobalConfigProvider) => _mergeWith(defaultGlobalConfig, injectConfig, (objValue, srcValue) => {
if (Array.isArray(objValue)) {
Expand Down
4 changes: 2 additions & 2 deletions src/config-provider/useConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed, inject, h } from '@vue/composition-api';
import { GlobalConfigProvider, defaultGlobalConfig, configProviderInjectKey } from './context';
import { GlobalConfigProvider, defaultGlobalConfig } from './context';

/**
* component global config
Expand All @@ -8,7 +8,7 @@ import { GlobalConfigProvider, defaultGlobalConfig, configProviderInjectKey } fr
* useConfig('pagination')
*/
export function useConfig<T extends keyof GlobalConfigProvider>(componentName?: T) {
const injectGlobalConfig = inject(configProviderInjectKey, null);
const injectGlobalConfig = inject<GlobalConfigProvider>('globalConfig', null);
const mergedGlobalConfig = computed(() => injectGlobalConfig?.value || defaultGlobalConfig);
const global = computed(() => mergedGlobalConfig.value[componentName]);

Expand Down

0 comments on commit 1ffbd38

Please sign in to comment.