<commit_before>import { hasStatusLoading } from "./lazyload.data";
import { decreaseLoadingCount } from "./lazyload.event";
import { resetSourcesImg } from "./lazyload.setSources";
import { safeCallback } from "./lazyload.callback";

export const cancelIfLoading = (element, entry, settings, instance) => {
    if (!settings.cancel_on_exit) return;
    if (!hasStatusLoading(element)) return;
    if (element.tagName !== "IMG") return;
    resetSourcesImg(element, settings, instance);
    decreaseLoadingCount(instance);
    safeCallback(settings.callback_cancel, element, entry, instance);
    // setTimeout is needed because the "callback_cancel" implementation
    // could be out of the main thread, e.g. `img.setAttribute("src", "")`
    setTimeout(() => {
        instance.resetElementStatus(element, instance);
    }, 0);
};<commit_msg>cancelIfLoading: Removing event listeners before resetting sources<commit_after>import { hasStatusLoading } from "./lazyload.data";
import { decreaseLoadingCount, removeEventListeners } from "./lazyload.event";
import { resetSourcesImg } from "./lazyload.setSources";
import { safeCallback } from "./lazyload.callback";

export const cancelIfLoading = (element, entry, settings, instance) => {
    if (!settings.cancel_on_exit) return;
    if (!hasStatusLoading(element)) return;
    if (element.tagName !== "IMG") return;
    removeEventListeners(element);
    resetSourcesImg(element, settings, instance);
    decreaseLoadingCount(instance);
    safeCallback(settings.callback_cancel, element, entry, instance);
    // setTimeout is needed because the "callback_cancel" implementation
    // could be out of the main thread, e.g. `img.setAttribute("src", "")`
    setTimeout(() => {
        instance.resetElementStatus(element, instance);
    }, 0);
};
{'fraction_non_alphanumeric': 0.13070077864293658, 'fraction_numerical': 0.0011123470522803114, 'mean_word_length': 4.711111111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5974869', 'n_tokens_mistral': 480, 'n_tokens_neox': 495, 'n_words': 130}