Skip to content

refactor(editor): streamline option updates and simplify change bubbling mechanism - #206

Merged
Aarebecca merged 3 commits into
antvis:mainfrom
xxMudCloudxx:refactor/option-updates
Feb 25, 2026
Merged

Aarebecca merged 3 commits into
antvis:mainfrom
xxMudCloudxx:refactor/option-updates

Conversation

@xxMudCloudxx

Copy link
Copy Markdown
Contributor

📝 背景 (Background)

在现有的配置项更新逻辑中,为了实现 变更冒泡(Bubble Up) 并确保通知顺序,系统采用了显式集合(Set)记录变更路径,并在处理结束后进行深度排序与二次遍历。

存在的问题:

  • 复杂度高: 路径解析与深拷贝逻辑带来了额外的计算开销。
  • 流程冗余: 显式的集合维护与排序步骤增加了代码的维护成本。

优化目标:
利用递归天然的执行顺序优化逻辑流转,在降低代码复杂度的同时,显著提升整体执行效率。


✨ 主要改动 (Changes)

1. 逻辑链路简化

  • 递归回溯: 通过让递归函数 applyOptionUpdatesInternal 返回变更状态(boolean),将原本离散的父路径收集过程转化为函数调用栈的自然回溯。
  • 状态透传: 移除了中间状态的存储介质,使逻辑更加纯粹。

2. 自然的执行序管理

  • 后序遍历应用: 利用递归“由深及浅”的特性,天然实现了冒泡通知。
  • 时序保证: 确保在通知父级更新时,子级状态已处理完成,无需再进行额外的显式排序。

3. 性能与依赖优化

  • 去依赖化: 移除了 lodash-es 的 cloneDeep 与 get 调用,大幅减少了内存占用与路径解析开销。
  • 轻量化处理: 精简了路径字符串的拆解操作,提升了更新过程的执行速度。
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @xxMudCloudxx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在重构配置项更新逻辑,以提升效率并简化变更冒泡机制。通过将原有的显式集合记录、深度排序和二次遍历的复杂流程,替换为基于递归的自然回溯机制,显著降低了代码复杂度。这一优化不仅减少了计算开销和维护成本,还确保了通知顺序的正确性,从而提升了整体执行效率。

Highlights

  • 逻辑链路简化: 通过递归函数 applyOptionUpdatesInternal 返回变更状态,将父路径收集过程自然地转化为函数调用栈的回溯,移除了显式集合存储。
  • 自然的执行序管理: 利用递归的“由深及浅”特性,天然实现了冒泡通知,确保子级状态处理完成后再通知父级,无需额外排序。
  • 性能与依赖优化: 移除了对 lodash-es 的 cloneDeep 和 get 依赖,减少了内存占用和路径解析开销,并精简了路径字符串操作。
Changelog
  • tests/unit/editor/utils/object.test.ts
    • 更新了 applyOptionUpdates 的导入路径。
    • 将测试套件的描述从 mergeOptions 更名为 applyOptionUpdates。
    • 新增了处理数组值和 null 值的测试用例。
    • 移除了一个关于根路径 '' 的 collector 调用预期。
    • 调整了 bubbleUp 模式下 collector 调用路径的预期顺序。
  • src/editor/utils/object.ts
    • 移除了 lodash-es 中 cloneDeep 和 get 的导入。
    • 重构了 applyOptionUpdates 函数,移除了显式的 parentPathsToNotify 集合和后续的排序及遍历逻辑。
    • 修改了内部递归函数 applyOptionUpdatesInternal,使其返回一个布尔值以指示当前分支是否有变更。
    • 删除了辅助函数 collectParentPaths。
    • 调整了处理 undefined 值的逻辑,仅当键实际存在于目标对象时才执行删除和通知。
    • 在 applyOptionUpdatesInternal 中实现了基于递归回溯的冒泡通知机制,确保了后序遍历的通知顺序。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This refactoring significantly simplifies change bubbling logic by leveraging recursion and removing some lodash-es dependencies, leading to clearer and more efficient code. However, it introduces a critical security vulnerability: the recursive merge implementation in applyOptionUpdatesInternal lacks protection against Prototype Pollution. This could allow an attacker to compromise the application by providing crafted objects with sensitive keys like __proto__. Additionally, there are two potential breaking changes related to bubbling notifications: they now pass mutable object references instead of deep-copied snapshots, and notifications for the root path ('') have been removed.

Comment thread src/editor/utils/object.ts Resolved
Comment thread src/editor/utils/object.ts Resolved
Comment thread src/editor/utils/object.ts Resolved
@codecov-commenter

codecov-commenter commented Feb 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.19%. Comparing base (d03fde1) to head (4b32e9b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #206      +/-   ##
==========================================
+ Coverage   45.95%   46.19%   +0.24%     
==========================================
  Files         338      338              
  Lines       27047    27048       +1     
  Branches     2202     2220      +18     
==========================================
+ Hits        12430    12496      +66     
+ Misses      14606    14541      -65     
  Partials       11       11              
Flag Coverage Δ
infographic 46.19% <100.00%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/editor/utils/object.ts 100.00% <100.00%> (+3.94%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@xxMudCloudxx
xxMudCloudxx force-pushed the refactor/option-updates branch from dd6c2d6 to 80663d2 Compare February 15, 2026 01:36
@xxMudCloudxx

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

您好,感谢您对配置项更新逻辑的重构。通过利用递归回溯,您成功地简化了代码,移除了对 lodash-es 的部分依赖,并优化了变更冒泡机制,使其更加优雅和高效。这是一个非常棒的改进!

我在代码中发现了一个关于变更检测的边缘情况下的缺陷,以及一个可以增强测试用例完整性的地方。请查看我的具体评论。修复这些小问题后,这次重构将更加完美。

Comment thread src/editor/utils/object.ts Resolved
@xxMudCloudxx xxMudCloudxx changed the title refactor: streamline option updates and simplify change bubbling mechanism Feb 15, 2026
@Aarebecca
Aarebecca merged commit 8ec730d into antvis:main Feb 25, 2026
1 check passed
Aarebecca pushed a commit to xxMudCloudxx/Infographic that referenced this pull request Feb 25, 2026
…ing mechanism (antvis#206)

* refactor: optimize option updates recursion

* fix(editor): ensure safe object updates and collector cloning

* fix: bubbling edge cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants