MCPcopy Index your code
hub / github.com/microsoft/SandDance / getClassNames

Function getClassNames

docs/app/js/sanddance-app.js:23419–23467  ·  view source on GitHub ↗
(styleFunctionOrObject, styleProps)

Source from the content-addressed store, hash-verified

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
23465 // cache the return value for this branch of the graph.
23466 return current[retVal];
23467 };
23468 return getClassNames;
23469}
23470function _traverseEdge(current, value) {

Callers 3

sanddance-app.jsFile · 0.85
getStylesFunction · 0.85
VerticalDividerBaseFunction · 0.85

Calls 4

_traverseMapFunction · 0.85
clearMethod · 0.65
warnMethod · 0.45
traceMethod · 0.45

Tested by

no test coverage detected