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

Function checkStylingMap

packages/core/src/render3/instructions/styling.ts:279–338  ·  view source on GitHub ↗
(
  keyValueArraySet: (keyValueArray: KeyValueArray<any>, key: string, value: any) => void,
  stringParser: (styleKeyValueArray: KeyValueArray<any>, text: string) => void,
  value: any | NO_CHANGE,
  isClassBased: boolean,
)

Source from the content-addressed store, hash-verified

277 * @param isClassBased `true` if `class` change (`false` if `style`)
278 */
279export function checkStylingMap(
280 keyValueArraySet: (keyValueArray: KeyValueArray<any>, key: string, value: any) => void,
281 stringParser: (styleKeyValueArray: KeyValueArray<any>, text: string) => void,
282 value: any | NO_CHANGE,
283 isClassBased: boolean,
284): void {
285 const tView = getTView();
286 const bindingIndex = incrementBindingIndex(2);
287 if (tView.firstUpdatePass) {
288 stylingFirstUpdatePass(tView, null, bindingIndex, isClassBased);
289 }
290 const lView = getLView();
291 if (value !== NO_CHANGE && bindingUpdated(lView, bindingIndex, value)) {
292 // `getSelectedIndex()` should be here (rather than in instruction) so that it is guarded by the
293 // if so as not to read unnecessarily.
294 const tNode = tView.data[getSelectedIndex()] as TNode;
295 if (hasStylingInputShadow(tNode, isClassBased) && !isInHostBindings(tView, bindingIndex)) {
296 if (ngDevMode) {
297 // verify that if we are shadowing then `TData` is appropriately marked so that we skip
298 // processing this binding in styling resolution.
299 const tStylingKey = tView.data[bindingIndex];
300 assertEqual(
301 Array.isArray(tStylingKey) ? tStylingKey[1] : tStylingKey,
302 false,
303 "Styling linked list shadow input should be marked as 'false'",
304 );
305 }
306 // VE does not concatenate the static portion like we are doing here.
307 // Instead VE just ignores the static completely if dynamic binding is present.
308 // Because of locality we have already set the static portion because we don't know if there
309 // is a dynamic portion until later. If we would ignore the static portion it would look like
310 // the binding has removed it. This would confuse `[ngStyle]`/`[ngClass]` to do the wrong
311 // thing as it would think that the static portion was removed. For this reason we
312 // concatenate it so that `[ngStyle]`/`[ngClass]` can continue to work on changed.
313 let staticPrefix = isClassBased ? tNode.classesWithoutHost : tNode.stylesWithoutHost;
314 ngDevMode &&
315 isClassBased === false &&
316 staticPrefix !== null &&
317 assertEqual(staticPrefix.endsWith(';'), true, "Expecting static portion to end with ';'");
318 if (staticPrefix !== null) {
319 // We want to make sure that falsy values of `value` become empty strings.
320 value = concatStringsWithSpace(staticPrefix, value ? value : '');
321 }
322 // Given `<div [style] my-dir>` such that `my-dir` has `@Input('style')`.
323 // This takes over the `[style]` binding. (Same for `[class]`)
324 setDirectiveInputsWhichShadowsStyling(tView, tNode, lView, value, isClassBased);
325 } else {
326 updateStylingMap(
327 tView,
328 tNode,
329 lView,
330 lView[RENDERER],
331 lView[bindingIndex + 1],
332 (lView[bindingIndex + 1] = toStylingKeyValueArray(keyValueArraySet, stringParser, value)),
333 isClassBased,
334 bindingIndex,
335 );
336 }

Callers 2

ɵɵstyleMapFunction · 0.85
ɵɵclassMapFunction · 0.85

Calls 14

getTViewFunction · 0.90
incrementBindingIndexFunction · 0.90
getLViewFunction · 0.90
bindingUpdatedFunction · 0.90
getSelectedIndexFunction · 0.90
assertEqualFunction · 0.90
concatStringsWithSpaceFunction · 0.90
stylingFirstUpdatePassFunction · 0.85
hasStylingInputShadowFunction · 0.85
isInHostBindingsFunction · 0.85
updateStylingMapFunction · 0.85

Tested by

no test coverage detected