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

Function findStylingValue

packages/core/src/render3/instructions/styling.ts:946–1004  ·  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

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