Skip to content

Commit

Permalink
Merge pull request #4446 from easyops-cn/steve/v3-config-merge-method
Browse files Browse the repository at this point in the history
Steve/v3-config-merge-method
  • Loading branch information
willc001 authored Sep 2, 2024
2 parents e9da7c6 + a238d37 commit eaf8e5b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/brick-container/src/loadBootstrapData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ jest.spyOn(http, "get").mockImplementation(async (url) => {
},
defaultConfig: {
defaultConf: 7,
array: [1, 2],
},
userConfig: {
__merge_method: "override",
userConf: 8,
array: [3],
},
menuIcon: {
imgSrc:
Expand Down Expand Up @@ -325,9 +328,12 @@ describe("loadBootstrapData", () => {
},
defaultConfig: {
defaultConf: 7,
array: [1, 2],
},
userConfig: {
__merge_method: "override",
userConf: 8,
array: [3],
},
menuIcon: {
imgSrc:
Expand Down Expand Up @@ -365,15 +371,20 @@ describe("loadBootstrapData", () => {
},
defaultConfig: {
defaultConf: 7,
array: [1, 2],
},
userConfig: {
__merge_method: "override",
userConf: 8,
array: [3],
runtimeUserConf: 9,
},
config: {
__merge_method: "override",
defaultConf: 7,
userConf: 8,
runtimeUserConf: 9,
array: [3],
},
menuIcon: {
imgSrc:
Expand Down
11 changes: 10 additions & 1 deletion packages/brick-container/src/loadBootstrapData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,16 @@ export async function fulfilStoryboard(storyboard: RuntimeStoryboard) {
}

function initializeAppConfig(app: MicroApp) {
app.config = deepFreeze(merge({}, app.defaultConfig, app.userConfig));
// Manually add `__merge_method: override` to avoid being deep merged.
const mergedConfig =
(app.userConfig?.__merge_method ?? app.defaultConfig?.__merge_method) ===
"override"
? {
...app.defaultConfig,
...app.userConfig,
}
: merge({}, app.defaultConfig, app.userConfig);
app.config = deepFreeze(mergedConfig);
}

function initializeAppLocales(app: MicroApp) {
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export interface RuntimeStoryboard extends Storyboard {
$$registerCustomTemplateProcessed?: boolean;
$$fulfilled?: boolean;
$$fulfilling?: Promise<void>;
$$fullMerged?: boolean;
$$i18nFulfilled?: boolean;
$$deadConditionsRemoved?: boolean;
}
Expand Down

0 comments on commit eaf8e5b

Please sign in to comment.