refactor: debounce leaf rerender, leaf will rerender too many times while creating new prop instance

This commit is contained in:
LeoYuan 袁力皓 2022-10-20 16:17:14 +08:00 committed by 林熠
parent 51aca3d330
commit ef3a540910
2 changed files with 4 additions and 4 deletions

View File

@ -386,7 +386,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
/** 监听参数变化 */ /** 监听参数变化 */
initOnPropsChangeEvent(leaf = this.leaf): void { initOnPropsChangeEvent(leaf = this.leaf): void {
const dispose = leaf?.onPropChange?.((propChangeInfo: PropChangeOptions) => { const dispose = leaf?.onPropChange?.(debounce((propChangeInfo: PropChangeOptions) => {
const { const {
key, key,
newValue = null, newValue = null,
@ -433,7 +433,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
}); });
this.judgeMiniUnitRender(); this.judgeMiniUnitRender();
}); }, 30));
dispose && this.disposeFunctions.push(dispose); dispose && this.disposeFunctions.push(dispose);
} }

View File

@ -16,8 +16,8 @@ jest.mock('lodash', () => {
return { return {
...original, ...original,
debounce: (fn) => () => fn(), debounce: (fn) => (...args: any[]) => fn.apply(this, args),
throttle: (fn) => () => fn(), throttle: (fn) => (...args: any[]) => fn.apply(this, args),
} }
}) })