I have two promises that get called when waiting for either A) an element to appear, or B) an element to disappear
* Wait for DOM element to Disappear
* @param {String} element DOM element to be watched
*/
export const elementVisibilityWatcherDisappear = ClientFunction((element) => {
return new Promise(resolve => {
var interval = setInterval(() => {
if (document.querySelector(element)){
return;
}
clearInterval(interval);
resolve();
}, 100);
});
})
/**
* Wait for DOM element to Appear
* @param {String} element DOM element to be watched
*/
export const elementVisibilityWatcherAppear = ClientFunction((element) => {
return new Promise(resolve => {
var interval = setInterval(() => {
if (!document.querySelector(element)){
return;
}
clearInterval(interval);
resolve();
}, 100);
});
})
What does document.querySelector(element)
return? Doesn't it return null
if the element wasn't found in the DOM? Thus for the method 'elementVisibilityWatcherDisappear' within the IF statement, wouldn't it return 'true' when the querySelector returns true and thus the promise is resolved...
HOWEVER, that is opposite of what I'm seeing. When calling the disappear method, the method does actually return when the element is no longer part of the dom... I'm just 100% confused WHY it does b/c the if statement logic suggests that it wouldn't...