Skip to content

Commit 2f3e7d4

Browse files
authored
Merge pull request webpack#7331 from dev-drprasad/add-jsdoc-annotations-cached-merge
📝 Add JSDoc annotations for cached merge util function
2 parents 70c608c + 10c850d commit 2f3e7d4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/util/cachedMerge.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66

77
const mergeCache = new WeakMap();
88

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+
* 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
21+
*/
922
const cachedMerge = (first, second) => {
1023
let innerCache = mergeCache.get(first);
1124
if (innerCache === undefined) {

0 commit comments

Comments
 (0)