-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
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, | ||
) |
There was a problem hiding this comment.
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.
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() | ||
} |
There was a problem hiding this comment.
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.
fix #36 |
No description provided.