---
title: "LazyWalker"
---
# LazyWalker

Defined in: [src/core/dom/lazy-walker.ts:26](https://github.com/xdan/jodit/blob/main/src/core/dom/lazy-walker.ts#L26)

Walks the DOM tree in small chunks between browser tasks so that even huge
documents do not block the main thread.

Events:
- `visit` - is called for every node; return `true` to mark the pass as
  "had effect" (it will be passed into the `end` event)
- `break` - the pass was interrupted via [LazyWalker.break](dom.LazyWalker.html#break)
- `end` - the pass is finished, receives `true` if some `visit` handler returned `true`

## Extends

- [`Eventify`](./event_emitter.Eventify.html)\<\{ `visit`: (`node`) => `boolean`; `break`: (`reason?`) => `void`; `end`: (`affect`) => `void`; \}\>

## Implements

- [`IDestructible`](../interfaces/types.IDestructible.html)

### Constructor

**new LazyWalker**(`async`, `options?`): `LazyWalker`

Defined in: [src/core/dom/lazy-walker.ts:60](https://github.com/xdan/jodit/blob/main/src/core/dom/lazy-walker.ts#L60)

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `async` | [`IAsync`](../interfaces/types.IAsync.html) | - |
| `options` | \{ `whatToShow?`: `number`; `reverse?`: `boolean`; `timeoutChunkSize?`: `number`; `timeout?`: `number`; \} | - |
| `options.whatToShow?` | `number` | Visit only nodes with this `nodeType` (e.g. `Node.ELEMENT_NODE`) |
| `options.reverse?` | `boolean` | Walk the tree from the last node to the first |
| `options.timeoutChunkSize?` | `number` | How many nodes are processed per one chunk. Default: 50 |
| `options.timeout?` | `number` | Delay between chunks in ms |

#### Returns

`LazyWalker`

#### Overrides

[`Eventify`](./event_emitter.Eventify.html).[`constructor`](./event_emitter.Eventify.html#constructor)

### setWork()

**setWork**(`root`): `this`

Defined in: [src/core/dom/lazy-walker.ts:40](https://github.com/xdan/jodit/blob/main/src/core/dom/lazy-walker.ts#L40)

Starts a new pass over the `root` tree.
If a previous pass is still running it will be stopped first.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `root` | [`Node`](https://developer.mozilla.org/docs/Web/API/Node) |

#### Returns

`this`

***

### break()

**break**(`reason?`): `void`

Defined in: [src/core/dom/lazy-walker.ts:88](https://github.com/xdan/jodit/blob/main/src/core/dom/lazy-walker.ts#L88)

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `reason?` | `string` |

#### Returns

`void`

***

### end()

**end**(): `void`

Defined in: [src/core/dom/lazy-walker.ts:95](https://github.com/xdan/jodit/blob/main/src/core/dom/lazy-walker.ts#L95)

#### Returns

`void`

***

### destruct()

**destruct**(): `void`

Defined in: [src/core/dom/lazy-walker.ts:111](https://github.com/xdan/jodit/blob/main/src/core/dom/lazy-walker.ts#L111)

#### Returns

`void`

#### Implementation of

[`IDestructible`](../interfaces/types.IDestructible.html).[`destruct`](../interfaces/types.IDestructible.html#destruct)

#### Overrides

[`Eventify`](./event_emitter.Eventify.html).[`destruct`](./event_emitter.Eventify.html#destruct)

***

### on()

**on**(`name`, `func`): `this`

Defined in: [src/core/event-emitter/eventify.ts:41](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/eventify.ts#L41)

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `name` | `"visit"` \| `"break"` \| `"end"` |
| `func` | ((`node`) => `boolean`) \| ((`reason?`) => `void`) \| ((`affect`) => `void`) |

#### Returns

`this`

#### Inherited from

[`Eventify`](./event_emitter.Eventify.html).[`on`](./event_emitter.Eventify.html#on)

***

### off()

**off**(`name`, `func`): `this`

Defined in: [src/core/event-emitter/eventify.ts:51](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/eventify.ts#L51)

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `name` | `"visit"` \| `"break"` \| `"end"` |
| `func` | ((`node`) => `boolean`) \| ((`reason?`) => `void`) \| ((`affect`) => `void`) |

#### Returns

`this`

#### Inherited from

[`Eventify`](./event_emitter.Eventify.html).[`off`](./event_emitter.Eventify.html#off)
