提交 6563a31a 编写于 作者: B Benjamin Pasero

progress - fix debouncer initial value

上级 49b4567a
......@@ -66,10 +66,10 @@ export interface IDebouceReducer<T> {
(previousValue: T, ...args: any[]): T;
}
export function debounce<T>(delay: number, reducer?: IDebouceReducer<T>, initialValue?: T): Function {
export function debounce<T>(delay: number, reducer?: IDebouceReducer<T>, initialValueProvider?: () => T): Function {
return createDecorator((fn, key) => {
const timerKey = `$debounce$${key}`;
let result = initialValue;
let result = initialValueProvider ? initialValueProvider() : void 0;
return function (this: any, ...args: any[]) {
clearTimeout(this[timerKey]);
......@@ -79,7 +79,10 @@ export function debounce<T>(delay: number, reducer?: IDebouceReducer<T>, initial
args = [result];
}
this[timerKey] = setTimeout(() => fn.apply(this, args), delay);
this[timerKey] = setTimeout(() => {
fn.apply(this, args);
result = initialValueProvider ? initialValueProvider() : void 0;
}, delay);
};
});
}
\ No newline at end of file
......@@ -83,7 +83,7 @@ class ProgressCallback extends Progress<IProgressStep> {
super(p => this.throttledReport(p));
}
@debounce(100, (result: IProgressStep, currentValue: IProgressStep) => mergeProgress(result, currentValue), Object.create(null))
@debounce(100, (result: IProgressStep, currentValue: IProgressStep) => mergeProgress(result, currentValue), () => Object.create(null))
throttledReport(p: IProgressStep): void {
this._proxy.$progressReport(this._handle, p);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册