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

Convert dom-ready package to TypeScript #67671

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/dom-ready/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ domReady( function () {

_Parameters_

- _callback_ `Callback`: A function to execute after the DOM is ready.

_Returns_

- `void`:
- _callback_ `VoidFunction`: A function to execute after the DOM is ready.

<!-- END TOKEN(Autogenerated API docs) -->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
/**
* @typedef {() => void} Callback
*
* TODO: Remove this typedef and inline `() => void` type.
*
* This typedef is used so that a descriptive type is provided in our
* automatically generated documentation.
*
* An in-line type `() => void` would be preferable, but the generated
* documentation is `null` in that case.
*
* @see https://github.com/WordPress/gutenberg/issues/18045
*/

/**
* Specify a function to execute when the DOM is fully loaded.
*
* @param {Callback} callback A function to execute after the DOM is ready.
* @param callback A function to execute after the DOM is ready.
*
* @example
* ```js
Expand All @@ -25,10 +11,8 @@
* //do something after DOM loads.
* } );
* ```
*
* @return {void}
*/
export default function domReady( callback ) {
export default function domReady( callback: VoidFunction ) {
if ( typeof document === 'undefined' ) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe( 'domReady', () => {
describe( 'when document readystate is complete', () => {
it( 'should call the callback.', () => {
const callback = jest.fn( () => {} );
// @ts-expect-error document.readyState is read-only
document.readyState = 'complete';
domReady( callback );
expect( callback ).toHaveBeenCalled();
Expand All @@ -23,6 +24,7 @@ describe( 'domReady', () => {
describe( 'when document readystate is interactive', () => {
it( 'should call the callback.', () => {
const callback = jest.fn( () => {} );
// @ts-expect-error document.readyState is read-only
document.readyState = 'interactive';
domReady( callback );
expect( callback ).toHaveBeenCalled();
Expand All @@ -32,6 +34,7 @@ describe( 'domReady', () => {
describe( 'when document readystate is still loading', () => {
it( 'should add the callback as an event listener to the DOMContentLoaded event.', () => {
const addEventListener = jest.fn( () => {} );
// @ts-expect-error document.readyState is read-only
document.readyState = 'loading';
Object.defineProperty( document, 'addEventListener', {
value: addEventListener,
Expand Down
Loading