Skip to content

Commit 29ddb49

Browse files
committed
refactor: ! Simplify code since we know we are observing just one element
1 parent f00ca4a commit 29ddb49

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/Renderer/QueryRenderer.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,23 +174,22 @@ class QueryRenderChild extends MarkdownRenderChild {
174174
return;
175175
}
176176

177-
this.observer = new IntersectionObserver((entries) => {
177+
this.observer = new IntersectionObserver(([entry]) => {
178178
if (!this.containerEl.isShown()) {
179179
return;
180180
}
181181

182-
for (const entry of entries) {
183-
// entry describes a single visibility change for the specific element we are observing.
184-
if (entry.isIntersecting) {
185-
this.queryResultsRenderer.query.debug(
186-
`[render][observer] Became visible, isCacheChangedSinceLastRedraw:${this.isCacheChangedSinceLastRedraw}`,
187-
);
188-
if (this.isCacheChangedSinceLastRedraw) {
189-
this.queryResultsRenderer.query.debug('[render][observer] ... updating search results');
190-
this.render({ tasks: this.plugin.getTasks(), state: this.plugin.getState() })
191-
.then()
192-
.catch((e) => console.error(e));
193-
}
182+
// entry describes a single visibility change for the specific element we are observing.
183+
// It is safe to assume `entry.target === this.containerEl` here.
184+
if (entry.isIntersecting) {
185+
this.queryResultsRenderer.query.debug(
186+
`[render][observer] Became visible, isCacheChangedSinceLastRedraw:${this.isCacheChangedSinceLastRedraw}`,
187+
);
188+
if (this.isCacheChangedSinceLastRedraw) {
189+
this.queryResultsRenderer.query.debug('[render][observer] ... updating search results');
190+
this.render({ tasks: this.plugin.getTasks(), state: this.plugin.getState() })
191+
.then()
192+
.catch((e) => console.error(e));
194193
}
195194
}
196195
});

0 commit comments

Comments
 (0)