MCPcopy Create free account
hub / github.com/angular/angular / findStylingValue

Function findStylingValue

packages/core/src/render3/instructions/styling.ts:943–1001  ·  view source on GitHub ↗

* Search for styling value with higher priority which is overwriting current value, or a * value of lower priority to which we should fall back if the value is `undefined`. * * When value is being applied at a location, related values need to be consulted. * - If there is a higher priority bindi

(
  tData: TData,
  tNode: TNode | null,
  lView: LView,
  prop: string,
  index: number,
  isClassBased: boolean,
)

Source from the content-addressed store, hash-verified

941 * @param isClassBased `true` if `class` (`false` if `style`)
942 */
943function findStylingValue(
944 tData: TData,
945 tNode: TNode | null,
946 lView: LView,
947 prop: string,
948 index: number,
949 isClassBased: boolean,
950): any {
951 // `TNode` to use for resolving static styling. Also controls search direction.
952 // - `TNode` search next and quit as soon as `isStylingValuePresent(value)` is true.
953 // If no value found consult `tNode.residualStyle`/`tNode.residualClass` for default value.
954 // - `null` search prev and go all the way to end. Return last value where
955 // `isStylingValuePresent(value)` is true.
956 const isPrevDirection = tNode === null;
957 let value: any = undefined;
958 while (index > 0) {
959 const rawKey = tData[index] as TStylingKey;
960 const containsStatics = Array.isArray(rawKey);
961 // Unwrap the key if we contain static values.
962 const key = containsStatics ? (rawKey as string[])[1] : rawKey;
963 const isStylingMap = key === null;
964 let valueAtLViewIndex = lView[index + 1];
965 if (valueAtLViewIndex === NO_CHANGE) {
966 // In firstUpdatePass the styling instructions create a linked list of styling.
967 // On subsequent passes it is possible for a styling instruction to try to read a binding
968 // which
969 // has not yet executed. In that case we will find `NO_CHANGE` and we should assume that
970 // we have `undefined` (or empty array in case of styling-map instruction) instead. This
971 // allows the resolution to apply the value (which may later be overwritten when the
972 // binding actually executes.)
973 valueAtLViewIndex = isStylingMap ? EMPTY_ARRAY : undefined;
974 }
975 let currentValue = isStylingMap
976 ? keyValueArrayGet(valueAtLViewIndex, prop)
977 : key === prop
978 ? valueAtLViewIndex
979 : undefined;
980 if (containsStatics && !isStylingValuePresent(currentValue)) {
981 currentValue = keyValueArrayGet(rawKey as KeyValueArray<any>, prop);
982 }
983 if (isStylingValuePresent(currentValue)) {
984 value = currentValue;
985 if (isPrevDirection) {
986 return value;
987 }
988 }
989 const tRange = tData[index + 1] as TStylingRange;
990 index = isPrevDirection ? getTStylingRangePrev(tRange) : getTStylingRangeNext(tRange);
991 }
992 if (tNode !== null) {
993 // in case where we are going in next direction AND we did not find anything, we need to
994 // consult residual styling
995 let residual = isClassBased ? tNode.residualClasses : tNode.residualStyles;
996 if (residual != null /** OR residual !=== undefined */) {
997 value = keyValueArrayGet(residual!, prop);
998 }
999 }
1000 return value;

Callers 1

updateStylingFunction · 0.85

Calls 5

keyValueArrayGetFunction · 0.90
getTStylingRangePrevFunction · 0.90
getTStylingRangeNextFunction · 0.90
isStylingValuePresentFunction · 0.85
isArrayMethod · 0.80

Tested by

no test coverage detected