Last active
February 9, 2024 16:43
-
-
Save efrec/328c00462bfd72e01d1d489e88936d9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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