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 {
const dispose = leaf?.onPropChange?.((propChangeInfo: PropChangeOptions) => {
const dispose = leaf?.onPropChange?.(debounce((propChangeInfo: PropChangeOptions) => {
const {
key,
newValue = null,
@ -433,7 +433,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
});
this.judgeMiniUnitRender();
});
}, 30));
dispose && this.disposeFunctions.push(dispose);
}

View File

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