JavaScript resources auto run, collect and dispose
-
Frame independent
-
Lightweight, zero runtime dependency
-
Typescript Support
$ npm install resource-scope
import { resourceScope } from "resource-scope";
const scope = eventScope();
scope.run(() => {
// resize
window.addEventListener("resize", () => console.log("resize"));
// IntersectionObserver
const intersectionObserver = new IntersectionObserver(() =>
console.log("IntersectionObserver"),
);
document.querySelectorAll("*").forEach((item) => {
intersectionObserver.observe(item);
});
// setInterval
setInterval(() => {
console.log("setInterval");
}, 1000);
});
scope.dispose();
-
addEventListener
-
intersectionObserver
-
setInterval
-
TODO...