* Update map based styling. * * Map based styling could be anything which contains more than one binding. For example `string`, * or object literal. Dealing with all of these types would complicate the logic so * instead this function expects that the complex input is first converted into normal
( tView: TView, tNode: TNode, lView: LView, renderer: Renderer, oldKeyValueArray: KeyValueArray<any>, newKeyValueArray: KeyValueArray<any>, isClassBased: boolean, bindingIndex: number, )
| 769 | * @param bindingIndex Binding index of the binding. |
| 770 | */ |
| 771 | function updateStylingMap( |
| 772 | tView: TView, |
| 773 | tNode: TNode, |
| 774 | lView: LView, |
| 775 | renderer: Renderer, |
| 776 | oldKeyValueArray: KeyValueArray<any>, |
| 777 | newKeyValueArray: KeyValueArray<any>, |
| 778 | isClassBased: boolean, |
| 779 | bindingIndex: number, |
| 780 | ) { |
| 781 | if ((oldKeyValueArray as KeyValueArray<any> | NO_CHANGE) === NO_CHANGE) { |
| 782 | // On first execution the oldKeyValueArray is NO_CHANGE => treat it as empty KeyValueArray. |
| 783 | oldKeyValueArray = EMPTY_ARRAY as any; |
| 784 | } |
| 785 | let oldIndex = 0; |
| 786 | let newIndex = 0; |
| 787 | let oldKey: string | null = 0 < oldKeyValueArray.length ? oldKeyValueArray[0] : null; |
| 788 | let newKey: string | null = 0 < newKeyValueArray.length ? newKeyValueArray[0] : null; |
| 789 | while (oldKey !== null || newKey !== null) { |
| 790 | ngDevMode && assertLessThan(oldIndex, 999, 'Are we stuck in infinite loop?'); |
| 791 | ngDevMode && assertLessThan(newIndex, 999, 'Are we stuck in infinite loop?'); |
| 792 | const oldValue = |
| 793 | oldIndex < oldKeyValueArray.length ? oldKeyValueArray[oldIndex + 1] : undefined; |
| 794 | const newValue = |
| 795 | newIndex < newKeyValueArray.length ? newKeyValueArray[newIndex + 1] : undefined; |
| 796 | let setKey: string | null = null; |
| 797 | let setValue: any = undefined; |
| 798 | if (oldKey === newKey) { |
| 799 | // UPDATE: Keys are equal => new value is overwriting old value. |
| 800 | oldIndex += 2; |
| 801 | newIndex += 2; |
| 802 | if (oldValue !== newValue) { |
| 803 | setKey = newKey; |
| 804 | setValue = newValue; |
| 805 | } |
| 806 | } else if (newKey === null || (oldKey !== null && oldKey < newKey!)) { |
| 807 | // DELETE: oldKey key is missing or we did not find the oldKey in the newValue |
| 808 | // (because the keyValueArray is sorted and `newKey` is found later alphabetically). |
| 809 | // `"background" < "color"` so we need to delete `"background"` because it is not found in the |
| 810 | // new array. |
| 811 | oldIndex += 2; |
| 812 | setKey = oldKey; |
| 813 | } else { |
| 814 | // CREATE: newKey's is earlier alphabetically than oldKey's (or no oldKey) => we have new key. |
| 815 | // `"color" > "background"` so we need to add `color` because it is in new array but not in |
| 816 | // old array. |
| 817 | ngDevMode && assertDefined(newKey, 'Expecting to have a valid key'); |
| 818 | newIndex += 2; |
| 819 | setKey = newKey; |
| 820 | setValue = newValue; |
| 821 | } |
| 822 | if (setKey !== null) { |
| 823 | updateStyling(tView, tNode, lView, renderer, setKey, setValue, isClassBased, bindingIndex); |
| 824 | } |
| 825 | oldKey = oldIndex < oldKeyValueArray.length ? oldKeyValueArray[oldIndex] : null; |
| 826 | newKey = newIndex < newKeyValueArray.length ? newKeyValueArray[newIndex] : null; |
| 827 | } |
| 828 | } |
no test coverage detected
searching dependent graphs…