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

Feat/namespace #45

Merged
merged 5 commits into from
Jan 17, 2025
Merged

Feat/namespace #45

merged 5 commits into from
Jan 17, 2025

Conversation

rick-hup
Copy link
Collaborator

No description provided.

Comment on lines +1 to +8
export function requestIdleCallback(callback: () => void) {
if (typeof requestIdleCallback !== 'undefined') {
requestIdleCallback(callback)
}
else {
setTimeout(callback, 50)
}
}

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)

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.

Comment on lines 21 to 22
: getClosestProjectingNode(this.state.visualElement.parent),
)

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)),

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.

Comment on lines 10 to 12
export * from './types'
export * from './animation'
export * from './utils'

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.

Comment on lines +13 to 14
export { useDragControls } from './features/gestures/drag/use-drag-controls'
export type { PanInfo } from './features/gestures/pan/PanSession'

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!, {

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.

Comment on lines 205 to 206
const prevAnimate = JSON.stringify(this.options.animate)
this.options = options

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.

Comment on lines 47 to +50
// ...Object.keys(pkg.dependencies || {}),
'vue',
'hey-listen',
'@vueuse/core',

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.

Comment on lines 52 to 53
output: [
{

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',
],
}

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.

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