Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻ refactor: update the cache name of intersect of element #556

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading