MCPcopy
hub / github.com/tinyplex/tinybase / mapEnsure

Function mapEnsure

src/common/map.ts:60–72  ·  view source on GitHub ↗
(
  map: Map<Key, Value>,
  key: Key,
  getDefaultValue: () => Value,
  hadExistingValue?: (value: Value) => void,
)

Source from the content-addressed store, hash-verified

58 });
59
60export const mapEnsure = <Key, Value>(
61 map: Map<Key, Value>,
62 key: Key,
63 getDefaultValue: () => Value,
64 hadExistingValue?: (value: Value) => void,
65): Value => {
66 if (!collHas(map, key)) {
67 mapSet(map, key, getDefaultValue());
68 } else {
69 hadExistingValue?.(mapGet(map, key) as Value);
70 }
71 return mapGet(map, key) as Value;
72};
73
74export const mapMatch = <MapValue, ObjValue>(
75 map: IdMap<MapValue>,

Callers 15

getResultStoreFunction · 0.90
getPreStoreFunction · 0.90
addPreStoreListenerFunction · 0.90
addSourceStoreListenersFunction · 0.90
setQueryDefinitionImplFunction · 0.90
writeGroupRowFunction · 0.90
_registerListenersFunction · 0.90
mergeContentOrChangesFunction · 0.90
mergeCellsOrValuesFunction · 0.90
cellChangedFunction · 0.90
addDefaultsToRowFunction · 0.90
setValidTablesSchemaFunction · 0.90

Calls 3

collHasFunction · 0.90
mapSetFunction · 0.70
mapGetFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…