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

fix: inViewOption does not working #37

Merged
merged 1 commit into from
Jan 14, 2025
Merged

fix: inViewOption does not working #37

merged 1 commit into from
Jan 14, 2025

Conversation

rick-hup
Copy link
Collaborator

No description provided.

Comment on lines 41 to +52
this.unmount = inView(
element,
(entry) => {
handleHoverEvent(this.state, entry, 'Enter')
return (endEvent) => {
handleHoverEvent(this.state, entry, 'Leave')
if (!once) {
return (endEvent) => {
handleHoverEvent(this.state, entry, 'Leave')
}
}
},
viewOptions,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error Handling Issue

The startObserver method sets up an observer with the inView function but does not include any error handling mechanisms. This could lead to unhandled exceptions if the inView function encounters errors, such as invalid arguments or issues with the browser's IntersectionObserver.

Recommendation:
Implement try-catch blocks around the inView function call to handle potential exceptions gracefully. This will improve the robustness of the observer setup and prevent the application from crashing due to unhandled errors.

Comment on lines +59 to +66
update(): void {
const { props, prevProps } = this.state.visualElement
const hasOptionsChanged = ['amount', 'margin', 'root'].some(
hasViewportOptionChanged(props as any, prevProps as any),
)
if (hasOptionsChanged) {
this.startObserver()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance Optimization

The update method uses a combination of .some() and a custom function hasViewportOptionChanged to check if observer options have changed, which might be inefficient if the properties list is large or changes infrequently.

Recommendation:
Consider optimizing the check by caching previous properties and comparing directly or using a more efficient method to detect changes. This could reduce the overhead of function calls and iterations, improving the performance of the update method.

@rick-hup
Copy link
Collaborator Author

fix #36

@rick-hup rick-hup merged commit 32401a7 into master Jan 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant