diff --git a/api-documents/kit.eventwatcher.md b/api-documents/kit.eventwatcher.md index b3d86e9..b5baa86 100644 --- a/api-documents/kit.eventwatcher.md +++ b/api-documents/kit.eventwatcher.md @@ -12,6 +12,15 @@ A Watcher based on event handlers. export declare class EventWatcher extends Watcher ``` +## Example + + +```ts +const e = new EventWatcher(ls).useForeach(node => console.log(node)) +document.addEventListener('event', e.eventListener) + +``` + ## Constructors | Constructor | Modifiers | Description | @@ -25,12 +34,3 @@ export declare class EventWatcher() => EventWatcher<T, Before, After, true> | Enable single mode. | | [eventListener](./kit.eventwatcher.eventlistener.md) | | () => void | Use this function as event listener to invoke watcher. | -## Example - - -```ts -const e = new EventWatcher(ls).useForeach(node => console.log(node)) -document.addEventListener('event', e.eventListener) - -``` - diff --git a/api-documents/kit.intervalwatcher.md b/api-documents/kit.intervalwatcher.md index 12c518c..276b588 100644 --- a/api-documents/kit.intervalwatcher.md +++ b/api-documents/kit.intervalwatcher.md @@ -12,6 +12,18 @@ A watcher based on time interval. export declare class IntervalWatcher extends Watcher ``` +## Example + + +```ts +new IntervalWatcher(ls) +.useForeach(node => { + console.log(node) +}) +.startWatch(1000) + +``` + ## Properties | Property | Modifiers | Type | Description | @@ -25,15 +37,3 @@ export declare class IntervalWatcher { - console.log(node) -}) -.startWatch(1000) - -``` - diff --git a/api-documents/kit.liveselector.md b/api-documents/kit.liveselector.md index 811a710..ecdae83 100644 --- a/api-documents/kit.liveselector.md +++ b/api-documents/kit.liveselector.md @@ -12,6 +12,19 @@ Create a live selector that can continuously select the element you want. export declare class LiveSelector ``` +## Remarks + +Call [\#evaluate](./kit.liveselector.evaluate.md) to evaluate the element. Falsy value will be ignored. + +## Example + + +```ts +const ls = new LiveSelector().querySelectorAll('a').map(x => x.href) +ls.evaluate() // returns all urls at the current time. + +``` + ## Constructors | Constructor | Modifiers | Description | @@ -51,16 +64,3 @@ export declare class LiveSelector | [slice(start, end)](./kit.liveselector.slice.md) | | Returns a section of an array. | | [sort(compareFn)](./kit.liveselector.sort.md) | | Sorts an array. | -## Remarks - -Call [\#evaluate](./kit.liveselector.evaluate.md) to evaluate the element. Falsy value will be ignored. - -## Example - - -```ts -const ls = new LiveSelector().querySelectorAll('a').map(x => x.href) -ls.evaluate() // returns all urls at the current time. - -``` - diff --git a/api-documents/kit.mutationobserverwatcher.md b/api-documents/kit.mutationobserverwatcher.md index a44f43c..6164426 100644 --- a/api-documents/kit.mutationobserverwatcher.md +++ b/api-documents/kit.mutationobserverwatcher.md @@ -12,6 +12,18 @@ A watcher based on MutationObserver export declare class MutationObserverWatcher extends Watcher ``` +## Example + + +```ts +new MutationObserverWatcher(ls) + .useForeach(node => { + console.log(node) + }) + .startWatch() + +``` + ## Constructors | Constructor | Modifiers | Description | @@ -29,18 +41,6 @@ export declare class MutationObserverWatcherYou must provide a reasonable MutationObserverInit to reduce dom events.https://mdn.io/MutationObserverInit | +| [startWatch(options)](./kit.mutationobserverwatcher.startwatch.md) | | Start an MutationObserverWatcher. | | [stopWatch()](./kit.mutationobserverwatcher.stopwatch.md) | | Stop the watcher | -## Example - - -```ts -new MutationObserverWatcher(ls) - .useForeach(node => { - console.log(node) - }) - .startWatch() - -``` - diff --git a/api-documents/kit.mutationobserverwatcher.startwatch.md b/api-documents/kit.mutationobserverwatcher.startwatch.md index 195a1f3..1b39d57 100644 --- a/api-documents/kit.mutationobserverwatcher.startwatch.md +++ b/api-documents/kit.mutationobserverwatcher.startwatch.md @@ -6,10 +6,6 @@ Start an MutationObserverWatcher. -You must provide a reasonable MutationObserverInit to reduce dom events. - -https://mdn.io/MutationObserverInit - Signature: ```typescript @@ -26,3 +22,9 @@ startWatch(options: MutationObserverInit): this; `this` +## Remarks + +You must provide a reasonable MutationObserverInit to reduce dom events. + +https://mdn.io/MutationObserverInit + diff --git a/api-documents/kit.valueref.md b/api-documents/kit.valueref.md index c323d90..99d8979 100644 --- a/api-documents/kit.valueref.md +++ b/api-documents/kit.valueref.md @@ -12,6 +12,20 @@ A `ref` object with `addListener` export declare class ValueRef ``` +## Example + + +```ts +const ref = new ValueRef(64) +function useRef() { + const [state, setState] = React.useState(ref.value) + React.useEffect(() => ref.addListener(e => setState(e))) + return state +} +ref.value = 42 // useRef will receive the new value + +``` + ## Constructors | Constructor | Modifiers | Description | @@ -32,17 +46,3 @@ export declare class ValueRef | [removeAllListener()](./kit.valueref.removealllistener.md) | | Remove all listeners | | [removeListener(fn)](./kit.valueref.removelistener.md) | | Remove a listener | -## Example - - -```ts -const ref = new ValueRef(64) -function useRef() { - const [state, setState] = React.useState(ref.value) - React.useEffect(() => ref.addListener(e => setState(e))) - return state -} -ref.value = 42 // useRef will receive the new value - -``` -