Skip to content

Commit 4e02b49

Browse files
Merge pull request #149 from opencomponents/add-lazy-ocs
add lazy ocs
2 parents 4033d06 + c48139b commit 4e02b49

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oc-client-browser",
3-
"version": "2.1.5",
3+
"version": "2.1.6",
44
"description": "OC browser client",
55
"main": "index.js",
66
"types": "index.d.ts",

src/oc-client.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,20 @@ export function createOc(oc) {
723723
}
724724

725725
if (this.#manageLifecycle) {
726-
oc.renderNestedComponent(this, () => {});
726+
if (this.getAttribute("loading") === "lazy") {
727+
const observer = new IntersectionObserver((entries) => {
728+
for (const entry of entries) {
729+
if (entry.isIntersecting) {
730+
observer.disconnect();
731+
oc.renderNestedComponent(this, () => {});
732+
break;
733+
}
734+
}
735+
});
736+
observer.observe(this);
737+
} else {
738+
oc.renderNestedComponent(this, () => {});
739+
}
727740
}
728741
}
729742

0 commit comments

Comments
 (0)