Skip to content

Commit

Permalink
Update docs to note splitTask being exported
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Jun 20, 2024
1 parent 0b1c7b0 commit 93d83c3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/reference-guides/interactivity-api/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@ const { state } = store("myPlugin", {
As mentioned above with [`wp-on`](#wp-on), [`wp-on-window`](#wp-on-window), and [`wp-on-document`](#wp-on-document), an async action should be used whenever the `async` versions of the aforementioned directives cannot be used due to the action requiring synchronous access to the `event` object. Synchronous access is reqired whenever the action needs to call `event.preventDefault()`, `event.stopPropagation()`, or `event.stopImmediatePropagation()`. To ensure that the action code does not contribute to a long task, you may manually yield to the main thread after calling the synchronous event API. For example:

```js
function toMainThread() {
// Note: In WordPress 6.6 this splitTask function is exported by @wordpress/interactivity.
function splitTask() {
return new Promise(resolve => {
setTimeout(resolve, 0);
});
Expand All @@ -823,7 +824,7 @@ store("myPlugin", {
actions: {
handleClick: function* (event) {
event.preventDefault();
yield toMainThread();
yield splitTask();
doTheWork();
},
},
Expand Down

0 comments on commit 93d83c3

Please sign in to comment.