Skip to content

Commit

Permalink
Merge pull request #7331 from dev-drprasad/add-jsdoc-annotations-cach…
Browse files Browse the repository at this point in the history
…ed-merge

📝 Add JSDoc annotations for cached merge util function
  • Loading branch information
sokra committed May 25, 2018
2 parents 70c608c + 10c850d commit 2f3e7d4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/util/cachedMerge.js
Expand Up @@ -6,6 +6,19 @@

const mergeCache = new WeakMap();

/**
* Merges two given objects and caches the result to avoid computation if same objects passed as arguements again.
* @example
* // performs Object.assign(first, second), stores the result in WeakMap and returns result
* cachedMerge({a: 1}, {a: 2})
* {a: 2}
* // when same arguments passed, gets the result from WeakMap and returns it.
* cachedMerge({a: 1}, {a: 2})
* {a: 2}
* @param {object} first first object
* @param {object} second second object
* @returns {object} merged object of first and second object
*/
const cachedMerge = (first, second) => {
let innerCache = mergeCache.get(first);
if (innerCache === undefined) {
Expand Down

0 comments on commit 2f3e7d4

Please sign in to comment.