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

Function classNamesFunction

docs/app/js/sanddance-app.js:23407–23469  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

23405// associated with the graph node.
23406var retVal = "__retval__";
23407function classNamesFunction(options) {
23408 // We build a trie where each node is a Map. The map entry key represents an argument
23409 // value, and the entry value is another node (Map). Each node has a `__retval__`
23410 // property which is used to hold the cached response.
23411 if (options === void 0) options = {};
23412 // To derive the response, we can simply ensure the arguments are added or already
23413 // exist in the trie. At the last node, if there is a `__retval__` we return that. Otherwise
23414 // we call the `getStyles` api to evaluate, cache on the property, and return that.
23415 var map = new Map();
23416 var styleCalcCount = 0;
23417 var getClassNamesCount = 0;
23418 var currentMemoizedClassNames = _memoizedClassNames;
23419 var getClassNames = function(styleFunctionOrObject, styleProps) {
23420 if (styleProps === void 0) styleProps = {};
23421 var _a, _b;
23422 // If useStaticStyles is true, styleFunctionOrObject returns slot to classname mappings.
23423 // If there is also no style overrides, we can skip merge styles completely and
23424 // simply return the result from the style funcion.
23425 if (options.useStaticStyles && typeof styleFunctionOrObject === "function" && styleFunctionOrObject.__noStyleOverride__) return styleFunctionOrObject(styleProps);
23426 getClassNamesCount++;
23427 var current = map;
23428 var theme = styleProps.theme;
23429 var rtl = theme && theme.rtl !== undefined ? theme.rtl : (0, _rtl.getRTL)();
23430 var disableCaching = options.disableCaching;
23431 // On reset of our stylesheet, reset memoized cache.
23432 if (currentMemoizedClassNames !== _memoizedClassNames) {
23433 currentMemoizedClassNames = _memoizedClassNames;
23434 map = new Map();
23435 styleCalcCount = 0;
23436 }
23437 if (!options.disableCaching) {
23438 current = _traverseMap(map, styleFunctionOrObject);
23439 current = _traverseMap(current, styleProps);
23440 }
23441 if (disableCaching || !current[retVal]) {
23442 if (styleFunctionOrObject === undefined) current[retVal] = {};
23443 else current[retVal] = (0, _mergeStyles.mergeCssSets)([
23444 typeof styleFunctionOrObject === "function" ? styleFunctionOrObject(styleProps) : styleFunctionOrObject,
23445 ], {
23446 rtl: !!rtl,
23447 specificityMultiplier: options.useStaticStyles ? DEFAULT_SPECIFICITY_MULTIPLIER : undefined
23448 });
23449 if (!disableCaching) styleCalcCount++;
23450 }
23451 if (styleCalcCount > (options.cacheSize || MAX_CACHE_COUNT)) {
23452 var win = (0, _dom.getWindow)();
23453 if ((_b = (_a = win) === null || _a === void 0 ? void 0 : _a.FabricConfig) === null || _b === void 0 ? void 0 : _b.enableClassNameCacheFullWarning) {
23454 // eslint-disable-next-line no-console
23455 console.warn("Styles are being recalculated too frequently. Cache miss rate is " + styleCalcCount + "/" + getClassNamesCount + ".");
23456 // eslint-disable-next-line no-console
23457 console.trace();
23458 }
23459 map.clear();
23460 styleCalcCount = 0;
23461 // Mutate the options passed in, that's all we can do.
23462 options.disableCaching = true;
23463 }
23464 // Note: the retVal is an attached property on the Map; not a key in the Map. We use this attached property to

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected