Skip to content

feat(code): add partial replace capability to extend method#425

Open
ader-h wants to merge 1 commit intoopentiny:devfrom
ader-h:feat-merge-0304
Open

feat(code): add partial replace capability to extend method#425
ader-h wants to merge 1 commit intoopentiny:devfrom
ader-h:feat-merge-0304

Conversation

@ader-h
Copy link
Contributor

@ader-h ader-h commented Mar 4, 2026

Summary by CodeRabbit

  • New Features
    • Enhanced configuration merging with support for partial replacements, allowing nested properties to be recursively merged instead of directly replaced when the partial flag is enabled.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

Walkthrough

The src/util/merge.js file is enhanced to support partial replacements through an extend.partial flag. When enabled, nested properties are recursively merged into the base option rather than being directly replaced.

Changes

Cohort / File(s) Summary
Merge Utility Enhancement
src/util/merge.js
Added conditional logic to check extend.partial flag; when truthy, performs recursive merge of nested properties; otherwise preserves original direct assignment behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A merge with grace, both new and old,
Through partial flags, the logic unfolds,
Recursive dreams replace what was before,
Nested properties dance forevermore! 🌿

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding partial replace capability to the extend method in the merge utility.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/util/merge.js`:
- Around line 65-74: The partial-merge branch of merge is dropping updates and
leaking control metadata; update the loop so it skips the control key 'partial',
and when merging do not ignore the returned value: compute const merged =
merge(baseOption[key] ?? {}, extend[key]) (or if baseOption[key] is a primitive,
coerce to an object/container first), then assign baseOption[key] = merged; keep
the Object.hasOwnProperty.call(extend, key) guard and ensure you don't mutate
extend or copy the 'partial' flag into baseOption.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 667a1b1c-4819-4cd9-b918-22dd9d5d5c4e

📥 Commits

Reviewing files that changed from the base of the PR and between 2d30e28 and a5f6752.

📒 Files selected for processing (1)
  • src/util/merge.js

Comment on lines 65 to +74
for (const key in extend) {
if (Object.hasOwnProperty.call(extend, key)) {
baseOption[key] = extend[key];
// 部分替换
if (extend.partial){
if (Object.hasOwnProperty.call(extend, key)) {
merge(baseOption[key], extend[key])
}
} else {
if (Object.hasOwnProperty.call(extend, key)) {
baseOption[key] = extend[key];
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix partial-merge path: it can drop updates and mutate with control metadata.

On Line 69, merge(baseOption[key], extend[key]) ignores the returned value, so new keys / some partial updates are lost. It can also fail when baseOption[key] is primitive and extend[key] is object. Also, the loop currently processes partial itself, which can leak control metadata into baseOption.

Proposed fix
 function mergeExtend(iChartOption, baseOption) {
     if (!iChartOption) return;
     let extend = iChartOption.extend;
     if (!extend) return;
     for (const key in extend) {
-        // 部分替换
-        if (extend.partial){
-            if (Object.hasOwnProperty.call(extend, key)) {
-                merge(baseOption[key], extend[key])
-            }
-        } else {
-            if (Object.hasOwnProperty.call(extend, key)) {
-                baseOption[key] = extend[key];
-            }
-        }
+        if (!Object.prototype.hasOwnProperty.call(extend, key) || key === 'partial') continue;
+        // 部分替换
+        if (extend.partial) {
+            if (isObject(extend[key]) && !isArray(extend[key])) {
+                const current = isObject(baseOption[key]) && !isArray(baseOption[key]) ? baseOption[key] : undefined;
+                baseOption[key] = merge(current, extend[key]);
+            } else {
+                baseOption[key] = extend[key];
+            }
+        } else {
+            baseOption[key] = extend[key];
+        }
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/util/merge.js` around lines 65 - 74, The partial-merge branch of merge is
dropping updates and leaking control metadata; update the loop so it skips the
control key 'partial', and when merging do not ignore the returned value:
compute const merged = merge(baseOption[key] ?? {}, extend[key]) (or if
baseOption[key] is a primitive, coerce to an object/container first), then
assign baseOption[key] = merged; keep the Object.hasOwnProperty.call(extend,
key) guard and ensure you don't mutate extend or copy the 'partial' flag into
baseOption.

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