Skip to content

Commit a9afd99

Browse files
committed
docs: whoops forgor outdated debounce props
1 parent f0075ff commit a9afd99

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

docs.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Additionally, there are the following extra options:
124124
- `disableOnNoListeners` - whether to disable the SelectorObserver when there are no listeners left (defaults to false)
125125
- `enableOnAddListener` - whether to enable the SelectorObserver when a new listener is added (defaults to true)
126126
- `defaultDebounce` - if set to a number, this debounce will be applied to every listener that doesn't have a custom debounce set (defaults to 0)
127-
- `defaultDebounceEdge` - can be set to "falling" (default) or "rising", to call the function at (rising) on the very first call and subsequent times after the given debounce time or (falling) the very last call after the debounce time passed with no new calls - [see `debounce()` for more info and a diagram](#debounce)
127+
- `defaultDebounceType` - can be set to "immediate" (default), to call the function on the very first call and subsequent times after the given debounce time passed, or "idle", to let through the very last call, after the debounce time passed with no subsequent calls - [see `Debouncer` for more info and a diagram](#debouncer)
128128
- `checkInterval` - if set to a number, the checks will be run on interval instead of on mutation events - in that case all MutationObserverInit props will be ignored
129129

130130
⚠️ Make sure to call `enable()` to actually start observing. This will need to be done after the DOM has loaded (when using `@run-at document-end` or after `DOMContentLoaded` has fired) **and** as soon as the `baseElement` or `baseElementSelector` is available.
@@ -154,8 +154,9 @@ The listener will be called immediately if the selector already exists in the DO
154154
> If `options.debounce` is set to a number above 0, this listener will be debounced by that amount of milliseconds (defaults to 0).
155155
> E.g. if the debounce time is set to 200 and the selector is found twice within 100ms, only the last call of this listener will be executed.
156156
157-
> `options.debounceEdge` is set to "falling" by default, which means the debounce timer will start after the last call of this listener.
158-
> If set to "rising", the debounce timer will start after the first call of this listener.
157+
> `options.debounceType` is set to "immediate" by default, which means the listener will be called immediately and then debounced on subsequent calls.
158+
> If set to "idle", the SelectorObserver will wait until the debounce time has passed with no new calls and then calls the listener with the latest element(s) found.
159+
> See the [Debouncer](#debouncer) class for a better explanation.
159160
160161
> When using TypeScript, the generic `TElement` can be used to specify the type of the element(s) that this listener will return.
161162
> It will default to HTMLElement if left undefined.
@@ -241,8 +242,8 @@ document.addEventListener("DOMContentLoaded", () => {
241242
attributeFilter: ["class", "style", "data-whatever"],
242243
// debounce all listeners by 100ms unless specified otherwise:
243244
defaultDebounce: 100,
244-
// "rising" means listeners are called immediately and use the debounce as a timeout between subsequent calls - see the debounce() function for a better explanation
245-
defaultDebounceEdge: "rising",
245+
// "immediate" means listeners are called immediately and use the debounce as a timeout between subsequent calls - see the Debouncer class for a better explanation
246+
defaultDebounceType: "immediate",
246247
// other settings from the MutationObserver API can be set here too - see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/observe#options
247248
});
248249

@@ -255,8 +256,8 @@ document.addEventListener("DOMContentLoaded", () => {
255256
barObserver.addListener("#my-other-element", {
256257
// set the debounce higher than provided by the defaultDebounce property:
257258
debounce: 250,
258-
// adjust the debounceEdge back to the default "falling" for this specific listener:
259-
debounceEdge: "falling",
259+
// change the type for this specific listener:
260+
debounceType: "idle",
260261
listener: (element) => {
261262
console.log("Other element's attributes changed:", element);
262263
},

0 commit comments

Comments
 (0)