Merge remote-tracking branch 'origin/master' into webpack5-upgrade-attempt

# Conflicts:
#	package.json
#	yarn.lock
This commit is contained in:
Roman committed 2022-01-26 13:05:44 +02:00
commit 55eebf38b7
47 files changed
+672 -658

No files matched your search

+11
View File
@@ -25,3 +25,14 @@ export function getOrInsert<K, V>(map: Map<K, V>, key: K, value: V): V {
export function getOrInsertMap<K, MK, MV>(map: Map<K, Map<MK, MV>>, key: K): Map<MK, MV> {
return getOrInsert(map, key, new Map<MK, MV>());
}
/**
* Like `getOrInsert` but with delayed creation of the item
*/
export function getOrInsertWith<K, V>(map: Map<K, V>, key: K, value: () => V): V {
if (!map.has(key)) {
map.set(key, value());
}
return map.get(key);
}