-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config): handle query config options (#9824)
Refs #9807 --------- Co-authored-by: Vladimír Gorej <[email protected]>
- Loading branch information
Showing
3 changed files
with
38 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,32 +8,49 @@ | |
* NOTE1: lodash.merge & lodash.mergeWith prefers to ignore undefined values | ||
* NOTE2: special handling of `domNode` option is now required as `deep-extend` will corrupt it (lodash.merge handles it correctly) | ||
* NOTE3: oauth2RedirectUrl and withCredentials options can be set to undefined. By expecting null instead of undefined, we can't use lodash.merge. | ||
* NOTE4: urls.primaryName needs to handled in special way, because it's an arbitrary property on Array instance | ||
* | ||
* TODO([email protected]): remove deep-extend in favor of lodash.merge | ||
*/ | ||
import deepExtend from "deep-extend" | ||
|
||
const merge = (target, ...sources) => { | ||
let domNode = Symbol.for("domNode") | ||
const sourcesWithoutDomNode = [] | ||
let primaryName = Symbol.for("primaryName") | ||
const sourcesWithoutExceptions = [] | ||
|
||
for (const source of sources) { | ||
if (Object.hasOwn(source, "domNode")) { | ||
domNode = source.domNode | ||
const sourceWithoutDomNode = { ...source } | ||
delete sourceWithoutDomNode.domNode | ||
sourcesWithoutDomNode.push(sourceWithoutDomNode) | ||
} else { | ||
sourcesWithoutDomNode.push(source) | ||
const sourceWithoutExceptions = { ...source } | ||
|
||
if (Object.hasOwn(sourceWithoutExceptions, "domNode")) { | ||
domNode = sourceWithoutExceptions.domNode | ||
delete sourceWithoutExceptions.domNode | ||
} | ||
|
||
if (Object.hasOwn(sourceWithoutExceptions, "urls.primaryName")) { | ||
primaryName = sourceWithoutExceptions["urls.primaryName"] | ||
delete sourceWithoutExceptions["urls.primaryName"] | ||
} else if ( | ||
Array.isArray(sourceWithoutExceptions.urls) && | ||
Object.hasOwn(sourceWithoutExceptions.urls, "primaryName") | ||
) { | ||
primaryName = sourceWithoutExceptions.urls.primaryName | ||
delete sourceWithoutExceptions.urls.primaryName | ||
} | ||
|
||
sourcesWithoutExceptions.push(sourceWithoutExceptions) | ||
} | ||
|
||
const merged = deepExtend(target, ...sourcesWithoutDomNode) | ||
const merged = deepExtend(target, ...sourcesWithoutExceptions) | ||
|
||
if (domNode !== Symbol.for("domNode")) { | ||
merged.domNode = domNode | ||
} | ||
|
||
if (primaryName !== Symbol.for("primaryName") && Array.isArray(merged.urls)) { | ||
merged.urls.primaryName = primaryName | ||
} | ||
|
||
return merged | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters