Skip to content

Instantly share code, notes, and snippets.

@efrec
Last active February 9, 2024 16:43
Show Gist options
  • Save efrec/328c00462bfd72e01d1d489e88936d9a to your computer and use it in GitHub Desktop.
Save efrec/328c00462bfd72e01d1d489e88936d9a to your computer and use it in GitHub Desktop.
// Use this script to lazy-load a Dataview query, delaying its execution:
// 1. Create a vault folder with a friendly name (e.g. 'lazy-query').
// 2. Create a file named 'view.js' containing the below code in that folder.
// 3. In a `dataviewjs` block, define a DQL query.
// 4. In the same block, lazily evaulate with `await dv.view('friendly-name', dql)`.
const rootNode = dv.el("div", "");
const rootView = rootNode.closest(".view-content");
const viewObserver = new IntersectionObserver(
(entries, o) => {
entries.map((entry) => {
if (entry.isIntersecting) {
dv.execute(input);
o.disconnect();
}
});
},
{
root: rootView,
rootMargin: "50px",
},
);
viewObserver.observe(rootNode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment