Skip to content

Commit 88da356

Browse files
committed
Remove duplicate code
1 parent ea878e3 commit 88da356

3 files changed

Lines changed: 4 additions & 35 deletions

File tree

lib/Onyx.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Storage from './storage';
77
import * as Logger from './Logger';
88
import cache from './OnyxCache';
99
import createDeferredTask from './createDeferredTask';
10+
import customizerForMergeWith from "./customizerForMergeWith";
1011

1112
// Keeps track of the last connectionID that was used so we can keep incrementing it
1213
let lastConnectionID = 0;
@@ -636,24 +637,6 @@ function hasPendingMergeForKey(key) {
636637
return Boolean(mergeQueue[key]);
637638
}
638639

639-
/**
640-
* When merging 2 objects into onyx that contain an array, we want to completely replace the array instead of the default
641-
* behavior which is to merge each item by its index.
642-
* ie:
643-
* merge({a: [1]}, {a: [2,3]}):
644-
* - In the default implementation would produce {a:[1,3]}
645-
* - With this function would produce: {a: [2,3]}
646-
* @param {*} objValue
647-
* @param {*} srcValue
648-
* @return {*}
649-
*/
650-
// eslint-disable-next-line rulesdir/prefer-early-return
651-
function customizerForMergeWith(objValue, srcValue) {
652-
if (_.isArray(objValue)) {
653-
return srcValue;
654-
}
655-
}
656-
657640
/**
658641
* Given an Onyx key and value this method will combine all queued
659642
* value updates and return a single value. Merge attempts are

lib/OnyxCache.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import _ from 'underscore';
22
import lodashMergeWith from 'lodash/mergeWith';
3+
import customizerForMergeWith from "./customizerForMergeWith";
34

45
const isDefined = _.negate(_.isUndefined);
56

@@ -105,20 +106,12 @@ class OnyxCache {
105106
delete this.storageMap[key];
106107
}
107108

108-
// eslint-disable-next-line rulesdir/prefer-early-return
109-
customizerForMergeWith(objValue, srcValue) {
110-
// TODO: this is duplicated from Onyx, reuse it instead
111-
if (_.isArray(objValue)) {
112-
return srcValue;
113-
}
114-
}
115-
116109
/**
117110
* Deep merge data to cache, any non existing keys will be created
118111
* @param {Record<string, *>} data - a map of (cache) key - values
119112
*/
120113
merge(data) {
121-
this.storageMap = lodashMergeWith({}, this.storageMap, data, this.customizerForMergeWith);
114+
this.storageMap = lodashMergeWith({}, this.storageMap, data, customizerForMergeWith);
122115

123116
const storageKeys = this.getAllKeys();
124117
const mergedKeys = _.keys(data);

lib/storage/providers/LocalForage.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@ import localforage from 'localforage';
88
import _ from 'underscore';
99
import lodashMergeWith from 'lodash/mergeWith';
1010
import SyncQueue from '../../SyncQueue';
11+
import customizerForMergeWith from "../../customizerForMergeWith";
1112

1213
localforage.config({
1314
name: 'OnyxDB',
1415
});
1516

16-
// eslint-disable-next-line rulesdir/prefer-early-return
17-
const customizerForMergeWith = function (objValue, srcValue) {
18-
// TODO: this is duplicated from Onyx, reuse it instead
19-
if (_.isArray(objValue)) {
20-
return srcValue;
21-
}
22-
};
23-
2417
const provider = {
2518
/**
2619
* Writing very quickly to IndexedDB causes performance issues and can lock up the page and lead to jank.

0 commit comments

Comments
 (0)