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(legacy-charts): tune chartoptions type check #821

Merged
merged 1 commit into from Apr 25, 2022
Merged

Conversation

thabarbados
Copy link
Collaborator

Fix or Enhancement?

tune legacy charts options type check

  • All tests passed

Environment

  • OS: BigSur MacOs
  • NPM Version: 8.5.1

@github-actions
Copy link

github-actions bot commented Apr 22, 2022

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
dist/index.cjs 1.16 KB (0%) 24 ms (0%) 100 ms (-8.11% 🔽) 123 ms
dist/index.js 1.04 KB (0%) 21 ms (0%) 103 ms (+12.1% 🔺) 124 ms

@@ -74,6 +74,7 @@ export function generateChart(chartId, chartType, chartController) {
computed: {
hasAnnotationPlugin() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
hasAnnotationPlugin() {
hasAnnotationPlugin() {
return this.chartOptions?.plugins?.hasOwnProperty(ANNOTATION_PLUGIN_KEY)

maybe better like that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dangreen Do not access Object.prototype method 'hasOwnProperty' from target object.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@thabarbados

Reflect.hasOwnProperty(this.chartOptions?.plugins, ANNOTATION_PLUGIN_KEY)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dangreen has the same error((

Copy link
Collaborator

Choose a reason for hiding this comment

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

@thabarbados

const plugins = this.chartOptions?.plugins

return plugins && Reflect.has(plugins, ANNOTATION_PLUGIN_KEY)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dangreen has Vue error in build version[Vue warn]: Property or method "chartOptions" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@thabarbados ok. please find short variant of current code, cause current variant is too long

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dangreen fixed

const pluginSettings =
this.chartOptions?.plugins?.[ANNOTATION_PLUGIN_KEY]

return pluginSettings !== undefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return pluginSettings !== undefined
return typeof pluginSettings !== 'undefined'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dangreen Used this option. I don't like Boolean)

Comment on lines 76 to 79
const pluginSettings =
this.chartOptions?.plugins?.[ANNOTATION_PLUGIN_KEY]

return pluginSettings !== undefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

or just

Suggested change
const pluginSettings =
this.chartOptions?.plugins?.[ANNOTATION_PLUGIN_KEY]
return pluginSettings !== undefined
return Boolen(this.chartOptions?.plugins?.[ANNOTATION_PLUGIN_KEY])

@dangreen dangreen merged commit 4409b98 into main Apr 25, 2022
@dangreen dangreen deleted the fix-type-check branch April 25, 2022 09:01
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.

None yet

2 participants