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: rewrite defineObjectProp logic #6556

Closed
wants to merge 1 commit into from
Closed

Conversation

BQXBQX
Copy link
Contributor

@BQXBQX BQXBQX commented Dec 14, 2024

Checklist
  • npm test passes
image
  • commit message follows commit guidelines
Description of change
  • Refactored logic to handle null and undefined parameters for proper storage.
  • Used Object.assign to merge objects without altering the outer reference.
  • Improved branching to handle different argument types clearly.
  • Enhanced code readability and extensibility.
  • Added 6551 test cases to ensure thorough validation of edge cases.
  • Fixed 树关系图给tooltip添加css样式无效 #6551

…e coverage

- Refactored logic to handle `null` and `undefined` parameters for proper storage.
- Used `Object.assign` to merge objects without altering the outer reference.
- Improved branching to handle different argument types clearly.
- Enhanced code readability and extensibility.
- Added 6551 test cases to ensure thorough validation of edge cases.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 12326417729

Details

  • 14 of 15 (93.33%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.002%) to 86.702%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/api/define.ts 14 15 93.33%
Totals Coverage Status
Change from base Build 12314197511: -0.002%
Covered Lines: 10622
Relevant Lines: 11875

💛 - Coveralls


case 2:
currentObj[key] = value;
return this.attr(k, currentObj);
Copy link
Member

Choose a reason for hiding this comment

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

感觉写法也有点复杂了😵‍💫

Copy link
Contributor Author

@BQXBQX BQXBQX Dec 14, 2024

Choose a reason for hiding this comment

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

是逻辑上的精简还是写法上的精简呢?逻辑优化上没有特别好的想法了,感觉逻辑再优化单测就出问题了 😵‍💫

Copy link
Member

@hustcc hustcc Dec 14, 2024

Choose a reason for hiding this comment

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

逻辑省不了,就是代码上了~我想想怎么归归类~

@hustcc
Copy link
Member

hustcc commented Dec 16, 2024

@BQXBQX 仔细想了一下,感觉不是很好规整。当前 defineObjectProp 有几种用法,分别是 单个设置、批量设置,这个 PR 的改动,是让 defineObjectProp 支持批量设置的 merge,可能带来几个问题:

  1. 代码上可能也更复杂了,并不比之前更易读,毕竟代码上功能更复杂了。

  2. 批量设置的用法上,针对 object、boolean、number、string 的逻辑其实不一致的,虽然是基本符合用户认知,但是前提是 defineObjectProp 的 API 都是 key value 形式的,也就是类似于 interaction、encode 这类,当前是符合的,但是担心未来可能有其他的形式,需要预留一些余量,比如:

chart.newAPI({ globalXXX: true })
  1. 做完 merge 操作之后,可能也会有另外的需求,就是是否需要 deepMerge?deepMerge 有会遇到数字的 merge 问题。其实有一种做不完的感觉。

所以建议:

  1. 维持现在的功能,object 的时候,就是覆盖。
  2. 尝试简化现有代码中 arguments.length 的逻辑
  3. 在文档中,标注出来两种用法和作用,告知 传入 object 就是全覆盖的操作,而非 megre。

你看看觉得如何?

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Dec 16, 2024

@BQXBQX 仔细想了一下,感觉不是很好规整。当前 defineObjectProp 有几种用法,分别是 单个设置、批量设置,这个 PR 的改动,是让 defineObjectProp 支持批量设置的 merge,可能带来几个问题:

  1. 代码上可能也更复杂了,并不比之前更易读,毕竟代码上功能更复杂了。
  2. 批量设置的用法上,针对 object、boolean、number、string 的逻辑其实不一致的,虽然是基本符合用户认知,但是前提是 defineObjectProp 的 API 都是 key value 形式的,也就是类似于 interaction、encode 这类,当前是符合的,但是担心未来可能有其他的形式,需要预留一些余量,比如:
chart.newAPI({ globalXXX: true })
  1. 做完 merge 操作之后,可能也会有另外的需求,就是是否需要 deepMerge?deepMerge 有会遇到数字的 merge 问题。其实有一种做不完的感觉。

所以建议:

  1. 维持现在的功能,object 的时候,就是覆盖。
  2. 尝试简化现有代码中 arguments.length 的逻辑
  3. 在文档中,标注出来两种用法和作用,告知 传入 object 就是全覆盖的操作,而非 megre。

你看看觉得如何?

好的,那我把文档说明加在 FAQ 里面可以吗?

@hustcc
Copy link
Member

hustcc commented Dec 16, 2024

需要在 这里 写的,这个文档目前都还没有 interaction 的 API。

export const commonProps = {
  encode: { type: 'object' },
  scale: { type: 'object' },
  data: { type: 'value' },
  transform: { type: 'array' },
  style: { type: 'object' },
  animate: { type: 'object' },
  coordinate: { type: 'object' },
  interaction: { type: 'object' },
  label: { type: 'array', key: 'labels' },
  axis: { type: 'object' },
  legend: { type: 'object' },
  slider: { type: 'object' },
  scrollbar: { type: 'object' },
  state: { type: 'object' },
  layout: { type: 'object' },
  theme: { type: 'object' },
  title: { type: 'value' },
} as const;

理论上,上面 type 是 object 的都是走的这个逻辑。

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Dec 17, 2024

需要在 这里 写的,这个文档目前都还没有 interaction 的 API。

export const commonProps = {
  encode: { type: 'object' },
  scale: { type: 'object' },
  data: { type: 'value' },
  transform: { type: 'array' },
  style: { type: 'object' },
  animate: { type: 'object' },
  coordinate: { type: 'object' },
  interaction: { type: 'object' },
  label: { type: 'array', key: 'labels' },
  axis: { type: 'object' },
  legend: { type: 'object' },
  slider: { type: 'object' },
  scrollbar: { type: 'object' },
  state: { type: 'object' },
  layout: { type: 'object' },
  theme: { type: 'object' },
  title: { type: 'value' },
} as const;

理论上,上面 type 是 object 的都是走的这个逻辑。

要是 type 是 object 都会出现这种情况,把这个问题放到 interaction 是不是有点不合适 🤕

@hustcc
Copy link
Member

hustcc commented Dec 17, 2024

感觉冗余点,都要加,这个就是文档难搞的一个点,跟着代码有区别。

@hustcc
Copy link
Member

hustcc commented Dec 17, 2024

要不这个先 hold 吧,明年我们做文档优化,一起来处理。

@hustcc hustcc closed this Dec 17, 2024
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.

树关系图给tooltip添加css样式无效
3 participants