MCPcopy Create free account
hub / github.com/microsoft/SandDance / createMemoizer

Function createMemoizer

docs/app/js/sanddance-app.js:24080–24094  ·  view source on GitHub ↗
(getValue)

Source from the content-addressed store, hash-verified

24078 };
24079}
24080function createMemoizer(getValue) {
24081 if (!_weakMap) // Without a `WeakMap` implementation, memoization is not possible.
24082 return getValue;
24083 var cache = new _weakMap();
24084 function memoizedGetValue(input) {
24085 if (!input || typeof input !== "function" && typeof input !== "object") // A WeakMap can only be used to test against reference values, i.e. 'function' and 'object'.
24086 // All other inputs cannot be memoized against in this manner.
24087 return getValue(input);
24088 if (cache.has(input)) return cache.get(input);
24089 var value = getValue(input);
24090 cache.set(input, value);
24091 return value;
24092 }
24093 return memoizedGetValue;
24094}
24095function _normalizeArg(val) {
24096 if (!val) return _emptyObject;
24097 else if (typeof val === "object" || typeof val === "function") return val;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected