We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 70c608c + 10c850d commit 2f3e7d4Copy full SHA for 2f3e7d4
lib/util/cachedMerge.js
@@ -6,6 +6,19 @@
6
7
const mergeCache = new WeakMap();
8
9
+/**
10
+ * Merges two given objects and caches the result to avoid computation if same objects passed as arguements again.
11
+ * @example
12
+ * // performs Object.assign(first, second), stores the result in WeakMap and returns result
13
+ * cachedMerge({a: 1}, {a: 2})
14
+ * {a: 2}
15
+ * // when same arguments passed, gets the result from WeakMap and returns it.
16
17
18
+ * @param {object} first first object
19
+ * @param {object} second second object
20
+ * @returns {object} merged object of first and second object
21
+ */
22
const cachedMerge = (first, second) => {
23
let innerCache = mergeCache.get(first);
24
if (innerCache === undefined) {
0 commit comments