Skip to content

Commit

Permalink
♻ refactor: update the cache name of intersect of element
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem committed Jan 31, 2024
1 parent e1d959d commit 1080edd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class ScrollToTargetJSInterop {
return;
}

if (el["_intersectForScrollToTarget"]) {
return;
}

const observer = new IntersectionObserver(
async (
entries: IntersectionObserverEntry[] = [],
Expand All @@ -40,8 +44,8 @@ class ScrollToTargetJSInterop {
this.options
);

el["_observe"] = Object(el["_observe"]);
el["_observe"] = { handle: this.handle, observer };
el["_intersectForScrollToTarget"] = Object(el["_intersectForScrollToTarget"]);
el["_intersectForScrollToTarget"] = { handle: this.handle, observer };

observer.observe(el);
}
Expand All @@ -50,11 +54,11 @@ class ScrollToTargetJSInterop {
const el = document.getElementById(id);
if (!el) return;

const observe = el["_observe"];
const observe = el["_intersectForScrollToTarget"];
if (!observe) return;

observe.observer.unobserve(el);
delete el["_observe"];
delete el["_intersectForScrollToTarget"];
}

dispose() {
Expand Down
10 changes: 5 additions & 5 deletions src/Component/BlazorComponent.Web/src/mixins/intersect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function observe(
return;
}

if (el["_observe"]) {
if (el["_intersect"]) {
return;
}

Expand Down Expand Up @@ -60,21 +60,21 @@ function observe(
standardOptions
);

el["_observe"] = Object(el["_observe"]);
el["_observe"] = { handle, observer };
el["_intersect"] = Object(el["_intersect"]);
el["_intersect"] = { handle, observer };

observer.observe(el);
}

function unobserve(el: HTMLElement) {
if (!el) return;

const observe = el["_observe"];
const observe = el["_intersect"];
if (!observe) return;

observe.observer.unobserve(el);
observe.handle.dispose();
delete el["_observe"];
delete el["_intersect"];
}

function observeSelector(
Expand Down

0 comments on commit 1080edd

Please sign in to comment.