You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+14-5
Original file line number
Diff line number
Diff line change
@@ -159,6 +159,7 @@ Additionally, there are the following extra options:
159
159
-`disableOnNoListeners` - whether to disable the SelectorObserver when there are no listeners left (defaults to false)
160
160
-`enableOnAddListener` - whether to enable the SelectorObserver when a new listener is added (defaults to true)
161
161
-`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)
162
+
-`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)
162
163
163
164
⚠️ 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.
164
165
@@ -177,16 +178,19 @@ The listener will be called immediately if the selector already exists in the DO
177
178
> This will also include elements that were already found in a previous listener call.
178
179
> If set to false (default), querySelector() will be used and only the first matching element will be returned.
179
180
180
-
> If `options.continuous` is set to true, the listener will not be deregistered after it was called once (defaults to false).
181
+
> If `options.continuous` is set to true, this listener will not be deregistered after it was called once (defaults to false).
181
182
>
182
-
> ⚠️ You should keep usage of this option to a minimum, as it will cause the listener to be called every time the selector is *checked for and found* and this can stack up quite quickly.
183
+
> ⚠️ You should keep usage of this option to a minimum, as it will cause this listener to be called every time the selector is *checked for and found* and this can stack up quite quickly.
183
184
> ⚠️ You should try to only use this option on SelectorObserver instances that are scoped really low in the DOM tree to prevent as many selector checks as possible from being triggered.
184
185
> ⚠️ I also recommend always setting a debounce time (see constructor or below) if you use this option.
185
186
186
-
> If `options.debounce` is set to a number above 0, the listener will be debounced by that amount of milliseconds (defaults to 0).
187
-
> E.g. if the debounce time is set to 200 and the selector is found twice within 100ms, only the last call of the listener will be executed.
187
+
> If `options.debounce` is set to a number above 0, this listener will be debounced by that amount of milliseconds (defaults to 0).
188
+
> 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.
189
+
190
+
> `options.debounceEdge` is set to "falling" by default, which means the debounce timer will start after the last call of this listener.
191
+
> If set to "rising", the debounce timer will start after the first call of this listener.
188
192
189
-
> When using TypeScript, the generic `TElement` can be used to specify the type of the element(s) that the listener will return.
193
+
> When using TypeScript, the generic `TElement` can be used to specify the type of the element(s) that this listener will return.
190
194
> It will default to HTMLElement if left undefined.
// debounce all listeners by 100ms unless specified otherwise:
264
268
defaultDebounce: 100,
269
+
// "rising" means listeners are called immediately and use the debounce as a timeout between subsequent calls - see the debounce() function for a better explanation
270
+
defaultDebounceEdge: "rising",
271
+
// other settings from the MutationObserver API can be set here too - see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/observe#options
0 commit comments