MCPcopy Create free account
hub / github.com/shoutem/theme / includeSymbolMergeHandler

Function includeSymbolMergeHandler

src/resolveIncludes.js:11–48  ·  view source on GitHub ↗
(objVal, srcVal)

Source from the content-addressed store, hash-verified

9 */
10// eslint-disable-next-line consistent-return
11function includeSymbolMergeHandler(objVal, srcVal) {
12 const newObjVal = objVal;
13 let include;
14
15 if (srcVal && srcVal[INCLUDE]) {
16 include =
17 newObjVal && newObjVal[INCLUDE]
18 ? [...newObjVal[INCLUDE], ...srcVal[INCLUDE]]
19 : srcVal[INCLUDE];
20 }
21
22 // if objVal doesn't exists create new from source
23 if (_.isUndefined(newObjVal) && _.isPlainObject(srcVal)) {
24 // Copy symbol fix.
25 // { ...srcVal } copies symbol wrong, it adds symbol value to the property defined just after it
26 // Problem example: { SYMBOL: ['Test'], someProp: 10 } => { someProp: ['Test'] }
27 // mergeWith prevents wrong copy because it doesn't iterate trough Symbols so it skips INCLUDE
28 // We do not INCLUDE symbol to be copied actually in this function
29 // because it is copied manually. This whole function is fixing Symbol problems.
30 const newObj = _.mergeWith({}, srcVal, (o, s) => s);
31 // Assigning INCLUDE after object definition to avoid Object.assign when code transpiled.
32 // Object.assign in RN uses polyfill which doesn't copy Symbols that's why INCLUDE symbol
33 // must be set manually after spread.
34 // TODO(Braco) - once Object.assign polyfill is no longer used use commented code bellow
35 // Check if `customizer` is needed still at all after polyfill is removed!
36 // return { ...srcVal, [INCLUDE]: include }; // add new lines for each property
37 if (include) {
38 newObj[INCLUDE] = include;
39 }
40 return newObj;
41 }
42
43 // otherwise let lodash default merge (return undefined)
44 // and add INCLUDE to objVal if any in srcVal
45 if (_.isPlainObject(newObjVal) && include) {
46 newObjVal[INCLUDE] = include;
47 }
48}
49
50/**
51 * Recursively include required target styles from target and base root.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected