MCPcopy
hub / github.com/angular/angular / findStylingValue

Function findStylingValue

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

907 * @param isClassBased `true` if `class` (`false` if `style`)
908 */
909function findStylingValue(
910 tData: TData,
911 tNode: TNode | null,
912 lView: LView,
913 prop: string,
914 index: number,
915 isClassBased: boolean,
916): any {
917 // `TNode` to use for resolving static styling. Also controls search direction.
918 // - `TNode` search next and quit as soon as `isStylingValuePresent(value)` is true.
919 // If no value found consult `tNode.residualStyle`/`tNode.residualClass` for default value.
920 // - `null` search prev and go all the way to end. Return last value where
921 // `isStylingValuePresent(value)` is true.
922 const isPrevDirection = tNode === null;
923 let value: any = undefined;
924 while (index > 0) {
925 const rawKey = tData[index] as TStylingKey;
926 const containsStatics = Array.isArray(rawKey);
927 // Unwrap the key if we contain static values.
928 const key = containsStatics ? (rawKey as string[])[1] : rawKey;
929 const isStylingMap = key === null;
930 let valueAtLViewIndex = lView[index + 1];
931 if (valueAtLViewIndex === NO_CHANGE) {
932 // In firstUpdatePass the styling instructions create a linked list of styling.
933 // On subsequent passes it is possible for a styling instruction to try to read a binding
934 // which
935 // has not yet executed. In that case we will find `NO_CHANGE` and we should assume that
936 // we have `undefined` (or empty array in case of styling-map instruction) instead. This
937 // allows the resolution to apply the value (which may later be overwritten when the
938 // binding actually executes.)
939 valueAtLViewIndex = isStylingMap ? EMPTY_ARRAY : undefined;
940 }
941 let currentValue = isStylingMap
942 ? keyValueArrayGet(valueAtLViewIndex, prop)
943 : key === prop
944 ? valueAtLViewIndex
945 : undefined;
946 if (containsStatics && !isStylingValuePresent(currentValue)) {
947 currentValue = keyValueArrayGet(rawKey as KeyValueArray<any>, prop);
948 }
949 if (isStylingValuePresent(currentValue)) {
950 value = currentValue;
951 if (isPrevDirection) {
952 return value;
953 }
954 }
955 const tRange = tData[index + 1] as TStylingRange;
956 index = isPrevDirection ? getTStylingRangePrev(tRange) : getTStylingRangeNext(tRange);
957 }
958 if (tNode !== null) {
959 // in case where we are going in next direction AND we did not find anything, we need to
960 // consult residual styling
961 let residual = isClassBased ? tNode.residualClasses : tNode.residualStyles;
962 if (residual != null /** OR residual !=== undefined */) {
963 value = keyValueArrayGet(residual!, prop);
964 }
965 }
966 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…