-
Notifications
You must be signed in to change notification settings - Fork 22
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
Feat/namespace #45
Feat/namespace #45
Conversation
…nimatePresence component
…mproved layout handling
export function requestIdleCallback(callback: () => void) { | ||
if (typeof requestIdleCallback !== 'undefined') { | ||
requestIdleCallback(callback) | ||
} | ||
else { | ||
setTimeout(callback, 50) | ||
} | ||
} |
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.
The function name requestIdleCallback
shadows the global requestIdleCallback
if it exists, which can lead to confusion or unexpected behavior. Consider renaming the function to something more distinct, like ensureRequestIdleCallback
, to avoid naming conflicts and improve code clarity.
requestIdleCallback(callback) | ||
} | ||
else { | ||
setTimeout(callback, 50) |
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.
The fallback delay of 50ms in setTimeout
is arbitrary and may not be optimal for all scenarios. Consider allowing the delay to be configurable via a function parameter, or justify the choice of 50ms with comments if it's based on specific requirements or benchmarks.
: getClosestProjectingNode(this.state.visualElement.parent), | ||
) |
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.
The ternary operation in line 21 assumes that options['data-framer-portal-id']
and this.state.visualElement.parent
are always defined. This could lead to runtime errors if these properties are undefined
at any point. Recommendation: Add null checks or default values to ensure that the properties accessed are always defined, or handle the potential undefined
cases explicitly to prevent runtime exceptions.
const options = this.state.options | ||
this.state.visualElement.projection.setOptions({ | ||
layout: options.layout, | ||
layoutId: options.layoutId, | ||
// TODO: drag | ||
alwaysMeasureLayout: false, | ||
alwaysMeasureLayout: Boolean(options.drag) || (options.dragConstraints && isHTMLElement(options.dragConstraints)), |
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.
The expression Boolean(options.drag) || (options.dragConstraints && isHTMLElement(options.dragConstraints))
in line 36 is used to determine the value of alwaysMeasureLayout
. This logic is complex and might be error-prone if options.dragConstraints
is not an HTMLElement but truthy. Recommendation: Refactor this condition to separate methods or add more explicit type checks to ensure that the logic is clear and maintainable.
export * from './types' | ||
export * from './animation' | ||
export * from './utils' |
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.
Using wildcard exports (export *
) in lines 10-12 can potentially lead to larger bundle sizes and increased load times for applications using this library, as they might include modules that are not actually used by the application. Consider explicitly exporting only the necessary modules to improve tree shaking and optimize the final bundle size.
export { useDragControls } from './features/gestures/drag/use-drag-controls' | ||
export type { PanInfo } from './features/gestures/pan/PanSession' |
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.
The specific exports from deeply nested paths in lines 13 and 14 suggest a potential issue with the encapsulation and abstraction of the module structure. This could make it difficult to refactor or reorganize internal structures without impacting consumers. Consider introducing a more layered architecture or intermediate modules that can re-export these functionalities in a more structured way.
* create visualElement | ||
*/ | ||
|
||
// Create visual element with initial config | ||
this.visualElement = createVisualElement(this.options.as!, { |
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.
The use of the non-null assertion operator (!
) in this.options.as!
can lead to runtime errors if as
is not provided in the options
. It's safer to handle potential undefined or null values explicitly to avoid such errors.
Recommendation:
Consider checking if as
is defined before using it, and provide a default value or throw a descriptive error if it's not provided.
const prevAnimate = JSON.stringify(this.options.animate) | ||
this.options = options |
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.
Comparing the animate
option by converting it to JSON strings is inefficient, especially for large objects, and can lead to performance issues.
Recommendation:
Instead of using JSON.stringify
, consider a more efficient method for deep comparison or use libraries like Lodash which offer optimized functions like _.isEqual
for deep comparison.
// ...Object.keys(pkg.dependencies || {}), | ||
'vue', | ||
'hey-listen', | ||
'@vueuse/core', |
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.
The external dependencies for the Rollup configuration are hardcoded (vue
, hey-listen
, @vueuse/core
). This approach is not scalable and requires manual updates whenever dependencies change. Consider dynamically generating this list from package.json
to improve maintainability and reduce the risk of errors. For example, you can uncomment and possibly fix the implementation in line 47:
// ...Object.keys(pkg.dependencies || {}),
This would automatically include all dependencies specified in package.json
as external, ensuring that updates to dependencies are seamlessly handled.
output: [ | ||
{ |
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.
The output configuration for the Rollup bundle is defined within an array, which might introduce unnecessary complexity if multiple formats are not actually required. If the project only needs one output format, consider simplifying this by using a single object instead of an array. This would make the configuration easier to read and maintain. If multiple formats are needed, ensure that each format is justified and clearly documented to avoid confusion.
@@ -25,6 +25,7 @@ export const utilities = { | |||
'useAnimationFrame', | |||
'useMotionValueEvent', | |||
'useLayoutGroup', | |||
'useDragControls', | |||
], | |||
} |
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.
The current structure of the utilities
object groups all utility functions under a single key, which might limit modularity and maintainability as the application scales or as more utilities are added. Consider restructuring this into a more flexible format, possibly by categorizing utilities into subgroups or using a more descriptive object structure that allows for easier extension and categorization. This change would make the codebase more scalable and maintainable.
No description provided.