Skip to content

Commit 10c850d

Browse files
committed
📝 Add annotations and description to cachedMerge util function
1 parent 217a657 commit 10c850d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/util/cachedMerge.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
"use strict";
66

77
const mergeCache = new WeakMap();
8+
89
/**
9-
* returns something
10-
* @param {object} first first key
11-
* @param {object} second second key
12-
* @returns {WeakMap} new merge
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+
* cachedMerge({a: 1}, {a: 2})
17+
* {a: 2}
18+
* @param {object} first first object
19+
* @param {object} second second object
20+
* @returns {object} merged object of first and second object
1321
*/
1422
const cachedMerge = (first, second) => {
1523
let innerCache = mergeCache.get(first);

0 commit comments

Comments
 (0)