v4.0.0
Major update 🚀
New Features
detector option for customized element detector
The option name is detector.optional
This is useful for use cases like wanting to fulfill after checking the state of an element. The return value type is explicitly defined, and when the condition is not fulfilled, it must return { isDetected: false }. Also, the resolved value of waitElement will be the returned result.
const waitPenguin = await waitElement("#animal", {
detector: (element) => {
return element?.textContent === "Penguin"
? { isDetected: true, result: element }
: { isDetected: false };
},
});AbortController is supported
The option name is signal.optional
You can now abort operations in the same way as the native fetch API.
const ac = new AbortController();
const checkElement = waitElement("#find", { signal: ac.signal });
await delay(300); // In fact, there will be some kind of process...
ac.abort("I feel like interrupting");Performance optimization for concurrent processing
The option name is unifyProcess.optional
This option is enabled(true) by default.
// all waitElement internal process unified
await Promise.all([
waitElement(".unify", {
unifyProcess: true,
}),
waitElement(".unify", {
unifyProcess: true,
}),
waitElement(".unify", {
unifyProcess: true,
}),
]);About the all options
Note
See TS definition for detailed options information.
BREAKING CHANGE
Warning
There are some breaking changes!
waitDisappearElement has been removed
To replicate waitDisappearElement in v4, use the following approach.
BEFORE
import { waitDisappearElement } from "@1natsu/wait-element";
await waitDisappearElement('.will-disappear');AFTER
import { isNotExist } from "@1natsu/wait-element/detectors";
await waitElement(".will-disappear", { detector: isNotExist });Timeout API has changed
The timeout option has been removed. Please use AbortSignal.timeout() instead.
BEFORE
await waitElement('.late-comming', { timeout: 5000 });AFTER
await waitElement('.late-comming', { signal: AbortSignal.timeout(5000) });Cancel API has changed
The cancelable API has been removed. Please use AbortController instead.
BEFORE
let el;
try {
el = waitElement('.cancelable');
if (!isCondition) el.cancel();
} catch {
// some handling...
}AFTER
const ac = new AbortController();
let el;
try {
el = waitElement(".aborted", {
signal: ac.signal,
});
if (!isCondition) ac.abort("abort!");
} catch (error) {
// some handling...
}Concurrent processing is now enabled by default
If you want to use concurrent processing as in v3, set unifyProcess to false.
await waitElement(".please-no-unify", {
unifyProcess: false,
});Changed logs
- version4 by @1natsu172 in #9
- add ci by @1natsu172 in #10
- Configure Renovate by @renovate in #3
- feat: beta.2 generics and resolve Result types by @1natsu172 in #12
- v4 ready by @1natsu172 in #13
Full Changelog: v3.0.0...v4.0.0