Home > @holoflows/kit > Watcher
Use LiveSelector to watch dom change
Signature:
export declare abstract class Watcher<T, Before extends Element, After extends Element, SingleMode extends boolean> implements PromiseLike<ResultOf<SingleMode, T>>
Implements: PromiseLike<ResultOf<SingleMode, T>>
Constructor |
Modifiers |
Description |
---|---|---|
Constructs a new instance of the |
Property |
Modifiers |
Type |
Description |
---|---|---|---|
|
DOMProxy<Node, Before, After> |
The first DOMProxy | |
|
{ warn(f?: (stack: string) => void): void; ignored: boolean; stack: string; } |
Warning to remember if developer forget to call the startWatch. | |
|
Partial<DOMProxyOptions<Before, After>> |
The dom proxy option used in DOMProxy() | |
|
(list: readonly T[], keys: readonly unknown[]) => (key: unknown) => T | null |
Find node from the given list by key | |
|
T extends Node ? DOMProxy<T, Before, After> : never |
This DOMProxy always point to the first node in the LiveSelector | |
|
boolean |
Is the watcher running | |
|
(a: unknown, b: unknown) => boolean |
Compare between | |
|
Map<unknown, useForeachReturns<T>> |
Saved callback map of last watch | |
|
Map<unknown, DOMProxy<any, Before, After>> |
Saved DOMProxy of last watch | |
|
readonly unknown[] |
Found key list of last watch | |
|
readonly T[] |
Found Node list of last watch | |
|
LiveSelector<T, SingleMode> |
The liveSelector that this object holds. | |
|
(node: T, index: number, arr: readonly T[]) => unknown |
Map | |
|
typeof requestIdleCallback |
window.requestIdleCallback, or polyfill. | |
|
() => void |
Schedule a watcher check | |
|
boolean |
Is the single mode is on. | |
|
useForeachReturns<T> |
(Optional) Callback for single mode | |
|
boolean |
Does it has a last iteration value in single mode? | |
|
T |
(Optional) Last iteration value for single mode | |
|
Parameters<Watcher<T, any, any, any>['useForeach']>[0] |
(Optional) Saved useForeach | |
|
(a: T, b: T) => boolean |
Compare between |
Method |
Modifiers |
Description |
---|---|---|
To help identify same nodes in different iteration, you need to implement a map function that map If the key is changed, the same node will call through | ||
| ||
Dismiss the warning that let you enable single mode but the warning is false positive. | ||
Get DOMProxy by key. DOMProxy will be unavailable if it is deleted | ||
If you're expecting Watcher may not be called, call this function, this will omit the warning. | ||
If you're expecting repeating keys, call this function, this will omit the warning. | ||
To help identify same nodes in different iteration, you need to implement a map function to compare You probably don't need this. | ||
Set option for DOMProxy | ||
Let the watcher start to watching | ||
Stop the watcher | ||
Start the watcher, once it emitted data, stop watching. | ||
Just like React hooks. Provide callbacks for each node changes. |