Skip to content

Commit 0823ea7

Browse files
committed
Add missing file, use it in default keys
1 parent 88da356 commit 0823ea7

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

lib/Onyx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ function initializeWithDefaultKeyStates() {
734734
.then((pairs) => {
735735
const asObject = _.object(pairs);
736736

737-
const merged = lodashMerge(asObject, defaultKeyStates);
737+
const merged = lodashMergeWith(asObject, defaultKeyStates, customizerForMergeWith);
738738
cache.merge(merged);
739739
_.each(merged, (val, key) => keyChanged(key, val));
740740
});

lib/customizerForMergeWith.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import _ from "underscore";
2+
3+
/**
4+
* When merging 2 objects into onyx that contain an array, we want to completely replace the array instead of the default
5+
* behavior which is to merge each item by its index.
6+
* ie:
7+
* merge({a: [1]}, {a: [2,3]}):
8+
* - In the default implementation would produce {a:[1,3]}
9+
* - With this function would produce: {a: [2,3]}
10+
* @param {*} objValue
11+
* @param {*} srcValue
12+
* @return {*}
13+
*/
14+
// eslint-disable-next-line rulesdir/prefer-early-return
15+
function customizerForMergeWith(objValue, srcValue) {
16+
if (_.isArray(objValue)) {
17+
return srcValue;
18+
}
19+
}
20+
21+
export default customizerForMergeWith;

0 commit comments

Comments
 (0)