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

allow set debounceTime #260

Merged
merged 3 commits into from
Jul 21, 2021
Merged

Conversation

0x0a0d
Copy link
Contributor

@0x0a0d 0x0a0d commented Jul 12, 2021

allow to change default 500ms at line 1583, that will be called at line 1529

src/index.js Outdated
@@ -1580,10 +1583,11 @@ module.exports = {
this.settings.routes.forEach(route => this.addRoute(route));

// Regenerate all auto aliases routes
const debounceTime = (debounceTime => (!isNaN(debounceTime) && debounceTime >= 0) ? debounceTime : 500)(parseInt(this.settings.debounceTime));
Copy link
Member

Choose a reason for hiding this comment

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

I feel it's a little too complicated. Just use a simply:
const debounceTime = debounceTime > 0 ? Number(this.settings.debounceTime) : 500

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean

  1. if this.settings.debounceTime is not set, parseInt will be NaN
  2. if this.settings.debounceTime is set, but
  • set to a wrong value likes 'a', parseInt will be NaN
  • debounceTime can not less than 0 too
  1. If pass all conditions, take return value from parseInt, else take default 500

This line is short for

function parseDebounceTime(settingValue) {
  const tmp = parseInt(settingValue);
  if (!isNaN(tmp) && tmp > 0) return tmp;
  else return 500
}
const debounceTime = parseDebounceTime(this.settings.debounceTime)

Copy link
Member

@icebob icebob Jul 20, 2021

Choose a reason for hiding this comment

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

I understand, but the logic is too complex. The option will be set by developers, and I don't want to protect the developers from themselves. If somebody set "a" for a debounceTime option....

Copy link
Member

Choose a reason for hiding this comment

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

@icebob backlog idea: maybe the fastest-validator would help here to check the configuration parameters?

@0x0a0d 0x0a0d requested a review from icebob July 19, 2021 00:29
src/index.js Outdated
@@ -1580,10 +1583,11 @@ module.exports = {
this.settings.routes.forEach(route => this.addRoute(route));

// Regenerate all auto aliases routes
const debounceTime = (debounceTime => (!isNaN(debounceTime) && debounceTime >= 0) ? debounceTime : 500)(parseInt(this.settings.debounceTime));
Copy link
Member

@icebob icebob Jul 20, 2021

Choose a reason for hiding this comment

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

I understand, but the logic is too complex. The option will be set by developers, and I don't want to protect the developers from themselves. If somebody set "a" for a debounceTime option....

@0x0a0d 0x0a0d requested a review from icebob July 21, 2021 00:16
src/index.js Outdated
@@ -1580,10 +1583,11 @@ module.exports = {
this.settings.routes.forEach(route => this.addRoute(route));

// Regenerate all auto aliases routes
const debounceTime = this.settings.debounceTime >= 0 ? parseInt(this.settings.debounceTime) : 500;
Copy link
Member

Choose a reason for hiding this comment

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

this.settings.debounceTime >= 0 is not correct. Just this.settings.debounceTime > 0

@0x0a0d
Copy link
Contributor Author

0x0a0d commented Jul 21, 2021 via email

@icebob
Copy link
Member

icebob commented Jul 21, 2021

Yeah, just null >= 0 is true, so if somebody set it to null it should be used the default 500 value.

@0x0a0d
Copy link
Contributor Author

0x0a0d commented Jul 21, 2021 via email

@0x0a0d 0x0a0d requested a review from icebob July 21, 2021 07:38
Copy link
Member

@icebob icebob left a comment

Choose a reason for hiding this comment

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

Thx!

@icebob icebob merged commit f708503 into moleculerjs:master Jul 21, 2021
@0x0a0d 0x0a0d deleted the allow_modify_debounce_time branch October 18, 2021 10:53
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.

3 participants