-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gh 9139 #2
base: master
Are you sure you want to change the base?
Conversation
} | ||
} catch (e) { | ||
console.error('Failed to refresh watch expressions: ', e); | ||
protected refreshWatchExpressions: () => Promise<void> = debounceAsync(() => this.refreshWatchExpressionsQueue = this.refreshWatchExpressionsQueue.then(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code did not return the property assignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read the file,,,but not quite understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function you are debouncing is different from before, it shouldn't be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified, pls check if it's correct now.
@@ -106,7 +106,7 @@ export class ScmInput implements Disposable { | |||
this.fireDidChange(); | |||
} | |||
|
|||
validate = debounce(async (): Promise<void> => { | |||
validate: () => Promise<void> = debounceAsync(async (): Promise<void> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't async () => {
enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async () => {
no debounce then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, with the debounce.
But I didn't see that the typing on arrow function wasn't from you. We can still remove it I assume?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate: () => Promise<void> = debounceAsync(async (): Promise<void> => { | |
validate: () => Promise<void> = debounceAsync(async () => { |
2611401
to
882e023
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to add different tests for different conditions.
For example:
- a
wait
time of 0 - different return types
@@ -0,0 +1,28 @@ | |||
/******************************************************************************** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since debounceAsync
is under promise-util.ts
, the spec file should also be under that name promise-util.spec.ts
.
describe('debounceAsync', () => { | ||
|
||
it('debounceAsync should return a promise', async () => { | ||
const promise = await debounceAsync( | ||
async () => 2 + 2, 50)(); | ||
expect(promise).to.equal(4); | ||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('debounceAsync', () => { | |
it('debounceAsync should return a promise', async () => { | |
const promise = await debounceAsync( | |
async () => 2 + 2, 50)(); | |
expect(promise).to.equal(4); | |
}); | |
}); | |
describe('promise-util', () => { | |
describe('#debounceAsync', () => { | |
it('should return a promise', async () => { | |
const promise = await debounceAsync( | |
async () => 2 + 2, 50)(); | |
expect(promise).to.equal(4); | |
}); | |
}); | |
}); |
|
||
describe('debounceAsync', () => { | ||
|
||
it('debounceAsync should return a promise', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the form 'should...
when describing individual tests.
const promise = await debounceAsync( | ||
async () => 2 + 2, 50)(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name promise
is likely incorrect here, since it is awaited
it is no longer a promise (as it has been resolved).
What it does
Fixes eclipse-theia#9139
We used more two libs for debouncing:
p-debounce
andlodash.debounce
,Since
lodash.debounce
is used more thanp-debounce
, we replacep-debounce
bylodash.debounce
where it used before.As
lodash.debounce
returnundefine
where our API ask for a promise type, we have to write adebounceAsync
function to wraplodash.debounce
and return an ideal type.This function is located at
@theia/core/lib/common/promise-util
. Other files where is needed import it.How to test
Some of the functions which use debounce are difficult to test.
it would be better to test the
debounceAsync
function in a test file:packages/core/src/common/promise-util.spec.ts
Review checklist
Reminder for reviewers