Skip to content

660 document new debouncer utility#683

Merged
hyyan merged 6 commits intomainfrom
660-document-new-debouncer-utility
Jan 26, 2026
Merged

660 document new debouncer utility#683
hyyan merged 6 commits intomainfrom
660-document-new-debouncer-utility

Conversation

@MatthewHawkins
Copy link
Copy Markdown
Member

No description provided.

Comment thread docs/docs/building-ui/debouncing.md Outdated
The `Debouncer` runs on the UI thread using webforJ's [`Interval`](/docs/advanced/interval) mechanism, so you don't need to wrap UI updates in `Environment.runLater()`.

:::tip
The delay parameter uses seconds as the unit, not milliseconds. Use `0.3f` for 300ms or `1.5f` for 1.5 seconds.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚫 [vale] reported by reviewdog 🐶
[Google.Units] Put a nonbreaking space between the number and the unit in '300ms'.

Comment thread docs/docs/building-ui/debouncing.md Outdated
});
```

## Debouncer vs ElementEventOptions {#debouncer-vs-elementeventoptions}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ [vale] reported by reviewdog 🐶
[Google.Headings] 'Debouncer vs ElementEventOptions' should use sentence-style capitalization.

Comment thread docs/docs/building-ui/debouncing.md Outdated

## Best practices {#best-practices}

1. **Choose appropriate delays**: Use shorter delays (200-300ms) for responsive interactions like search, and longer delays (1-2s) for expensive operations like auto-save.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚫 [vale] reported by reviewdog 🐶
[Google.Units] Put a nonbreaking space between the number and the unit in '300ms'.

Comment thread docs/docs/building-ui/debouncing.md Outdated

## Best practices {#best-practices}

1. **Choose appropriate delays**: Use shorter delays (200-300ms) for responsive interactions like search, and longer delays (1-2s) for expensive operations like auto-save.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚫 [vale] reported by reviewdog 🐶
[Google.Units] Put a nonbreaking space between the number and the unit in '2s'.

Comment thread docs/docs/building-ui/debouncing.md Outdated

2. **Reuse debouncer instances**: Create one `Debouncer` instance and reuse it rather than creating new instances on each event.

3. **Flush before critical actions**: Call `flush()` before form submission or navigation to ensure pending actions complete.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ [vale] reported by reviewdog 🐶
[webforJ.BeDirect] Avoid using 'ensure pending'. Focus more on explicitly giving details about the feature.

@hyyan
Copy link
Copy Markdown
Member

hyyan commented Jan 14, 2026

@MatthewHawkins I see some unrelated changes in the PR and a version change in the POM. Please clean that up and mark the PR as ready for review when it's done.

@hyyan hyyan added the status: needs-snapshot Update to the latest snapshot before this PR can be merged. label Jan 14, 2026
@MatthewHawkins MatthewHawkins added the status: waiting-for-review The PR is ready. Waiting for team members to review. label Jan 14, 2026
Comment thread docs/docs/advanced/debouncing.md Outdated
@@ -0,0 +1,196 @@
---
sidebar_position: 11
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move section to advanced

Comment thread docs/docs/building-ui/debouncing.md Outdated

The `Debouncer` runs on the UI thread using webforJ's [`Interval`](/docs/advanced/interval) mechanism, so you don't need to wrap UI updates in `Environment.runLater()`.

:::tip
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Give this tip a title

Comment thread docs/docs/building-ui/debouncing.md Outdated
The delay parameter uses seconds as the unit, not milliseconds. Use `0.3f` for 300ms or `1.5f` for 1.5 seconds.
:::

## API methods {#api-methods}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove the API methods section. You already cover them later.


The following methods can be used to more precisely handle the execution and use of the `Debouncer`:

### Cancelling a pending action {#cancelling-a-pending-action}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Explain that, like intervals. It's good practice to cancel the interval when the component is destroyed.

Comment thread docs/docs/building-ui/debouncing.md Outdated
}
```

## Use cases {#use-cases}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove section

```

## Debouncer vs ElementEventOptions {#debouncer-vs-elementeventoptions}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rename section to Choosing between Debouncer and event debounce options

Comment thread docs/docs/building-ui/debouncing.md Outdated
}, options);
```

## Best practices {#best-practices}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove section

private final TextField input = new TextField();
private final Paragraph output = new Paragraph();
private final Paragraph counter = new Paragraph();
private final Debouncer debounce = new Debouncer(0.5f);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cancel the debouncer when component is destroyed

@hyyan hyyan added status: waiting-for-author Review is done. Waiting for the PR author to apply changes or respond. and removed status: waiting-for-review The PR is ready. Waiting for team members to review. labels Jan 15, 2026
@MatthewHawkins MatthewHawkins self-assigned this Jan 20, 2026
@hyyan hyyan self-requested a review January 22, 2026 10:59
count++;
counter.setText("Key events: " + count);

debounce.run(() -> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rest count when debounce is done

@MatthewHawkins MatthewHawkins added status: waiting-for-review The PR is ready. Waiting for team members to review. and removed status: waiting-for-author Review is done. Waiting for the PR author to apply changes or respond. labels Jan 22, 2026
@hyyan hyyan merged commit 9773a7e into main Jan 26, 2026
@hyyan hyyan deleted the 660-document-new-debouncer-utility branch January 26, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs-snapshot Update to the latest snapshot before this PR can be merged. status: waiting-for-review The PR is ready. Waiting for team members to review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document new Debouncer utility

3 participants