Skip to content

Commit

Permalink
feat!: Update DOMisReady to accept Document argument and update depen…
Browse files Browse the repository at this point in the history
…dencies
  • Loading branch information
rafaucau committed Jul 2, 2023
1 parent d9adeec commit de85c05
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 142 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,31 @@ document.body.appendChild(button);
---

## `DOMisReady`
`DOMisReady` is a Promise that resolves when the DOM is ready, i.e., when the document's `readyState` is not 'loading'. This can be used to delay script execution until the DOM is fully constructed and can be safely manipulated.

`DOMisReady` is a function that returns a Promise. This Promise resolves when the provided DOM is ready, i.e., when the document's readyState is not 'loading'. This can be used to delay script execution until the DOM is fully constructed and can be safely manipulated.
```typescript
import { DOMisReady } from 'ts-dom-utils';
import { DOMisReady, qs } from 'ts-dom-utils';

// using then
DOMisReady.then(() => {
DOMisReady().then(() => {
// DOM manipulation code here
});

// using async/await
await DOMisReady;
// DOM manipulation code here
```
(async function() {
await DOMisReady();
// DOM manipulation code here
})();

// checking if an iframe's document is ready
const iframe = qs<HTMLIFrameElement>('iframe');
DOMisReady(iframe.contentDocument).then(() => {
// iframe DOM manipulation code here
});

```
| Param | Default | Description |
|-------|-----------|-------------------------|
| doc | document | The Document to check. |
---

### `qs`
Expand Down
Loading

0 comments on commit de85c05

Please sign in to comment.