Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Gh 9139 #2

wants to merge 1 commit into from

Conversation

smart-bo
Copy link
Owner

@smart-bo smart-bo commented Oct 29, 2021

What it does

Fixes eclipse-theia#9139

We used more two libs for debouncing: p-debounce and lodash.debounce,
Since lodash.debounce is used more than p-debounce , we replace p-debounce by lodash.debounce where it used before.

As lodash.debounce return undefine where our API ask for a promise type, we have to write a debounceAsync function to wrap lodash.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

}
} catch (e) {
console.error('Failed to refresh watch expressions: ', e);
protected refreshWatchExpressions: () => Promise<void> = debounceAsync(() => this.refreshWatchExpressionsQueue = this.refreshWatchExpressionsQueue.then(async () => {

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.

Copy link
Owner Author

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.

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.

Copy link
Owner Author

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> => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't async () => { enough?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async () => { no debounce then

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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
validate: () => Promise<void> = debounceAsync(async (): Promise<void> => {
validate: () => Promise<void> = debounceAsync(async () => {

Copy link

@vince-fugnitto vince-fugnitto left a 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 @@
/********************************************************************************

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.

Comment on lines 20 to 28
describe('debounceAsync', () => {

it('debounceAsync should return a promise', async () => {
const promise = await debounceAsync(
async () => 2 + 2, 50)();
expect(promise).to.equal(4);
});

});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 () => {

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.

Comment on lines 23 to 24
const promise = await debounceAsync(
async () => 2 + 2, 50)();

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[quality] Use one lib for debounce.
3 participants